我在Windows 7上安装了MSYS2,并成功地执行了
pacman -S mingw-w64-x86_64-gtk3(根据Step 2 of 为Windows设置GTK)和
pacman -S mingw-w64-x86_64-toolchain base-devel但是,当我试图编译你好,世界时
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位shell,输出是
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发布于 2021-06-27 10:22:44
以上是为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:\msys64\mingw64\bin添加到sys PATH中:它没有显示运行时错误,但是exe实际上不起作用(应用程序没有像预期的那样显示)。
AFAICS gtk4-demo-application本身在我的Windows上运行得不太好,所以最后我不得不恢复到GTK3,并编译了这个示例GTK3入门
gcc `pkg-config --cflags gtk+-3.0` -o example-1 example-1.c `pkg-config --libs gtk+-3.0`上面的编译和运行都很好。
运行时问题的解决方案
否则,可以选择不使用在Windows上从源代码构建GTK4而不使用MSYS2。
这张便条很重要
它在我的VirtualBox机器上是开箱即用的,但是在我的物理PC上使用英特尔GPU,我在启动时就崩溃了:
Unhandled exception at 0x5211345E (ig4icd32.dll) in gtk4-demo.exe: 0xC0000005: Access violation reading location 0x00000050可以通过使用cairo呈现来解决这个问题:
C:\src\gtk>set GSK_RENDERER=cairo
C:\src\gtk>C:\gnome\bin\gtk4-demo.exe结论: GTK4在MSYS2上的应用
总之,set GSK_RENDERER=cairo与运行在MSYS2下编译的可执行文件的修复相同,因此最终的解决方案包括
pacman -S mingw-w64-x86_64-gtk4C:\msys64\mingw64\bin;系统环境变量的开头添加PATHGSK_RENDERER添加一个新的cairo系统环境变量https://stackoverflow.com/questions/68150104
复制相似问题