I've installed MSYS2 on Windows 7 and I have successfully executed
pacman -S mingw-w64-x86_64-gtk3
(the above as per Step 2 of Setting up GTK for Windows) and
pacman -S mingw-w64-x86_64-toolchain base-devel
but when I try to compile the hello world with
gcc -o hello-world-gtk hello-world-gtk.c `pkg-config --cflags --libs gtk4`
I get the following
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
If I try from MinGW 64-bit shell the output is
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.
I've also checked that
$ echo $PKG_CONFIG_PATH
/mingw64/lib/pkgconfig:/mingw64/share/pkgconfig
the above as per Step 2 of Setting up GTK for Windows
They seem to have some outdated instructions on their site.
I actually have had to setup the following package
pacman -S mingw-w64-x86_64-gtk4
Then I could compile the example but it is not running fine. I still get a runtime error:
---------------------------
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.
Looking at this issue I've tried adding C:\msys64\mingw64\bin
to my sys PATH
: it does not show the runtime error but the exe is really not working anyway (the app does not show up as expected).
AFAICS gtk4-demo-application
itself is not running fine on my Windows, so finally I've had to revert to GTK3 and I compiled the example the GTK3 getting started
gcc `pkg-config --cflags gtk+-3.0` -o example-1 example-1.c `pkg-config --libs gtk+-3.0`
and the above compiles and runs fine.
Otherwise, there is the option to build GTK4 on Windows from source without MSYS2.
It is very important this note
It works out of the box on my VirtualBox machine, however on my physical PC with an intel GPU, I get a crash at startup:
Unhandled exception at 0x5211345E (ig4icd32.dll) in gtk4-demo.exe: 0xC0000005: Access violation reading location 0x00000050
This can be worked around by using cairo rendering:
C:\src\gtk>set GSK_RENDERER=cairo
C:\src\gtk>C:\gnome\bin\gtk4-demo.exe
In conclusion set GSK_RENDERER=cairo
is the same fix that does the trick also to run the executable compiled under MSYS2, therefore the final solution consists of
pacman -S mingw-w64-x86_64-gtk4
C:\msys64\mingw64\bin;
in the start of the PATH
system environment variableGSK_RENDERER
system environment variable with value cairo