在pkg配置搜索路径中找不到包gtk4



我在Windows 7上安装了MSYS2,并成功执行了

pacman -S mingw-w64-x86_64-gtk3

(以上根据设置Windows GTK的步骤2(和

pacman -S mingw-w64-x86_64-toolchain base-devel

但是当我试图用编译hello世界时

gcc -o hello-world-gtk hello-world-gtk.c `pkg-config --cflags --libs gtk4`

我得到以下

Package gtk4 was not found in the pkg-config search path.
Perhaps you should add the directory containing `gtk4.pc'
to the PKG_CONFIG_PATH environment variable
Package 'gtk4', required by 'virtual:world', not found
bash: gcc: command not found

如果我尝试从MinGW 64位外壳输出

MyHome@MyHome-PC MINGW64 ~
$ gcc -o hello-world-gtk hello-world-gtk.c `pkg-config --cflags --libs gtk4`
Package gtk4 was not found in the pkg-config search path.
Perhaps you should add the directory containing `gtk4.pc'
to the PKG_CONFIG_PATH environment variable
Package 'gtk4', required by 'virtual:world', not found
hello-world-gtk.c:1:10: fatal error: gtk/gtk.h: No such file or directory
1 | #include <gtk/gtk.h>
|          ^~~~~~~~~~~
compilation terminated.

我还检查了

$ echo $PKG_CONFIG_PATH
/mingw64/lib/pkgconfig:/mingw64/share/pkgconfig

根据为Windows 设置GTK的步骤2

他们的网站上似乎有一些过时的说明

我实际上已经设置了以下包

pacman -S mingw-w64-x86_64-gtk4

几个可能的运行时问题

然后我可以编译这个例子,但它运行得不好。我仍然得到一个运行时错误:

---------------------------
hello-world-gtk.exe - Errore di sistema
---------------------------
Impossibile avviare il programma perché libgio-2.0-0.dll non è presente nel computer. Per risolvere il problema, provare a reinstallare il programma. 

考虑到这个问题,我尝试将C:msys64mingw64bin添加到我的系统PATH:它不会显示运行时错误,但exe确实无法正常工作(应用程序没有按预期显示(。

AFAICSgtk4-demo-application本身在我的Windows上运行不好,所以最后我不得不恢复到GTK3,并编译了GTK3启动的示例

gcc `pkg-config --cflags gtk+-3.0` -o example-1 example-1.c `pkg-config --libs gtk+-3.0`

并且上面的编译并运行fine。

运行时问题的解决方案

否则,可以选择在没有MSYS2的情况下从源代码在Windows上构建GTK4。

这是非常重要的注意

它在我的VirtualBox机器上开箱即用,但在我的带有英特尔GPU的物理PC上,我在启动时崩溃:

Unhandled exception at 0x5211345E (ig4icd32.dll) in gtk4-demo.exe: 0xC0000005: Access violation reading location 0x00000050

这可以通过使用cairo渲染来解决:

C:srcgtk>set GSK_RENDERER=cairo
C:srcgtk>C:gnomebingtk4-demo.exe

结论:GTK4在MSYS2上的程序

总之,set GSK_RENDERER=cairo是与相同的修复程序,还可以运行在MSYS2下编译的可执行文件,因此最终解决方案由组成

  • 安装pacman -S mingw-w64-x86_64-gtk4
  • PATH系统环境变量的开头添加C:msys64mingw64bin;
  • 添加值为cairo的新GSK_RENDERER系统环境变量
  • 使用MSYS2 MinGW 64位shell进行编译(作为GTK4(并运行exe

最新更新