c - MSYS2 上运行时缺少 libcairo-2.dll

标签 c cairo msys2

下面是开始编写在 MSYS2 上使用 Cairo 的代码的简单测试:

#include <cairo.h>

int main() {
  cairo_surface_t *surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 300, 300);
  cairo_t *cr = cairo_create(surface);

  cairo_set_line_width(cr, 10.0);
  cairo_set_source_rgb(cr, 0, 0, 0);
  cairo_move_to(cr, 10.0, 10.0);
  cairo_line_to(cr, 100.0, 100.0);
  cairo_stroke(cr);

  cairo_destroy(cr);
  cairo_surface_write_to_png(surface, "c.png");
  cairo_surface_destroy(surface);

  return 0;
}

此代码使用以下命令在 Darwin/MacPorts 上正确构建和执行:

$ gcc c.c -o c `pkg-config cairo --libs --cflags`

在Win8/MSYS2下,我已经安装了mingw-w64-x86_64-cairo包。相同的 gcc 构建命令成功,但运行生成的可执行文件会导致以下错误:

C:/msys64/path/to/c.exe: error while loading shared libraries: libcairo-2.dll: cannot open shared object file: No such file or directory

我尝试在 MSYS2 中查找 libcairo-2.dll,但我什么也没看到。 Google 搜索并没有让我更接近。

我怀疑这是 MSYS2 开发学习曲线的一部分;我错过了什么?

最佳答案

运行编译后的可执行文件时,您的 PATH 环境变量中是否有 /mingw64/bin

libcairo-2.dll(以及许多其他 .dll 文件)位于 /mingw64/bin 中。

这个问题已经在 MinGW shell 中得到解决,它与 MSYS2 shell 不同。两者都在开始菜单中。

关于c - MSYS2 上运行时缺少 libcairo-2.dll,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33901680/

相关文章:

c++ - 链接器错误,使用 g++ 链接到 gcc 编译的库,未定义对该函数的引用

C 代码获取相对于 UTC 的本地时间偏移量(以分钟为单位)?

python - django操作系统错误: no library called "cairo" was found on windows

go - 将 Go 语言与 MSYS2 一起使用

c++ - 为什么来自 MSYS2 的 GNU MP (gmplib) 意外地将 ull 转换为 32 位整数?

gtk - 如何在 Windows 7+ 和 MSYS2 上的 GTK3 上获得原生窗口装饰

c# - 在 .NET Compact Framework 的托管代码 (C#) 中使用非托管 (C) 缓冲区

c - 如何在 gcc 中使用 brk()/sbrk()

python - 如何使 gtk.Layout 透明