Issues to build GTK4 on Windows with Meson


I’m on Windows 10 and MingW64 installed with Msys64.

I downloaded the GTK4 source from GNOME / gtk · GitLab
I followed the “Building and installing” section and downloaded required lib to build the GTK4 with Meson/Ninja.

When I run the 2nd command “meson compile -C_build”, I have the following errors:

D:\Coding\Cpp\gtk>meson compile -C_build
INFO: autodetecting backend as ninja
INFO: calculating backend command to run: D:\Computing\msys64\mingw64\bin\ninja.EXE -C D:/Coding/Cpp/gtk/_build
ninja: Entering directory `D:/Coding/Cpp/gtk/_build’
[1/1719] Generating gdk/gdkmarshalers_h with a custom command
FAILED: gdk/gdkmarshalers.h
“D:/Computing/msys64/mingw64/bin/…/bin/glib-genmarshal” “–prefix” “_gdk_marshal” “–valist-marshallers” “–output” “gdk/gdkmarshalers.h” “–header” “…/gdk/gdkmarshalers.list” “–pragma-once”
Cannot open
[6/1719] Generating gtk/css/gtkcssenumtypes.h with a custom command (wrapped by meson to capture output)
FAILED: gtk/css/gtkcssenumtypes.h
“D:\Program Files\Python3\Scripts\meson” “–internal” “exe” “–capture” “gtk/css\gtkcssenumtypes.h” “–” “D:/Computing/msys64/mingw64/bin/…/bin/glib-mkenums” “–template” “D:/Coding/Cpp/gtk/_build/…/gtk/css/gtkcssenumtypes.h.template” “D:/Coding/Cpp/gtk/_build/…/gtk/css/gtkcssenums.h” “D:/Coding/Cpp/gtk/_build/…/gtk/css/gtkcsserror.h” “D:/Coding/Cpp/gtk/_build/…/gtk/css/gtkcsslocation.h” “D:/Coding/Cpp/gtk/_build/…/gtk/css/gtkcsssection.h”
— stderr —
Cannot open

I don’t know why I have the “cannot open” error. When I look in the “MingW64/bin” folder I have these files:

  • glib-genmarshal.exe
  • glib-mkenums.exe

In the “” file I find:

build gdk/gdkmarshalers.h: CUSTOM_COMMAND …/gdk/gdkmarshalers.list | D$:/Computing/msys64/mingw64/bin/…/bin/glib-genmarshal
COMMAND = “D:/Computing/msys64/mingw64/bin/…/bin/glib-genmarshal” “–prefix” “_gdk_marshal” “–valist-marshallers” “–output” “gdk/gdkmarshalers.h” “–header” “…/gdk/gdkmarshalers.list” “–pragma-once”
description = Generating$ gdk/gdkmarshalers_h$ with$ a$ custom$ command


build gtk/css/gtkcssenumtypes.h: CUSTOM_COMMAND D$:/Coding/Cpp/gtk/_build/…/gtk/css/gtkcssenumtypes.h.template D$:/Coding/Cpp/gtk/_build/…/gtk/css/gtkcssenums.h D$:/Coding/Cpp/gtk/_build/…/gtk/css/gtkcsserror.h D$:/Coding/Cpp/gtk/_build/…/gtk/css/gtkcsslocation.h D$:/Coding/Cpp/gtk/_build/…/gtk/css/gtkcsssection.h | D$:/Computing/msys64/mingw64/bin/…/bin/glib-mkenums
COMMAND = “D:\Program$ Files\Python3\Scripts\meson” “–internal” “exe” “–capture” “gtk/css\gtkcssenumtypes.h” “–” “D:/Computing/msys64/mingw64/bin/…/bin/glib-mkenums” “–template” “D:/Coding/Cpp/gtk/_build/…/gtk/css/gtkcssenumtypes.h.template” “D:/Coding/Cpp/gtk/_build/…/gtk/css/gtkcssenums.h” “D:/Coding/Cpp/gtk/_build/…/gtk/css/gtkcsserror.h” “D:/Coding/Cpp/gtk/_build/…/gtk/css/gtkcsslocation.h” “D:/Coding/Cpp/gtk/_build/…/gtk/css/gtkcsssection.h”
description = Generating$ gtk/css/gtkcssenumtypes.h$ with$ a$ custom$ command$ (wrapped$ by$ meson$ to$ capture$ output)

I don’t know why he tries to open “” file…
Any ideas ?

I would like to compile the GTK4 demo in this process.


Never saw this error…

Do you use the mingw64 environment from MSYS2 as described here, or is it a custom setup?

Yes it’s from your link page

I remember that I didn’t have “glib-genmarshal” or “glib-mkenums” file, so Ninja fails because it didn’t find these files.
So I created them manually by coping “glib-genmarshal.exe” or “glib-mkenums.exe” and removed the “.exe” extension after.
Now Ninja find the files, but I have this error.

When I open the “glib-genmarshal.exe” file in a text editor, I can find “-script.” in the binary using notepad++.
When I run “glib-mkenums.exe”, it displays in the shell output:

/* This file is generated by glib-mkenums, do not modify it. This code is licensed under the same license as the containing project. Note that it links to GLib, so must comply with the LGPL linking clauses. /
Generated data ends here */

Not sure what’s going on.

I forced to update MSYS and all my packages with “pacman -Syu”.
I deleted the subfolder “_build”
I ran again “meson setup _build” and I notice now that in the “” file in subfolder “_build”, I have now “glib-mkenums.exe” with “.exe” extension instead of “glib-mkenums” without it:

build gtk/css/gtkcssenumtypes.c: CUSTOM_COMMAND D$:/Coding/Cpp/gtk/_build/…/gtk/css/gtkcssenumtypes.c.template D$:/Coding/Cpp/gtk/_build/…/gtk/css/gtkcssenums.h D$:/Coding/Cpp/gtk/_build/…/gtk/css/gtkcsserror.h D$:/Coding/Cpp/gtk/_build/…/gtk/css/gtkcsslocation.h D$:/Coding/Cpp/gtk/_build/…/gtk/css/gtkcsssection.h | D$:/Computing/msys64/mingw64/bin/…/bin/glib-mkenums.exe gtk/css/gtkcssenumtypes.h
COMMAND = “D:\Program$ Files\Python3\Scripts\meson” “–internal” “exe” “–capture” “gtk/css\gtkcssenumtypes.c” “–” “D:/Computing/msys64/mingw64/bin/…/bin/glib-mkenums.exe” “–template” “D:/Coding/Cpp/gtk/_build/…/gtk/css/gtkcssenumtypes.c.template” “D:/Coding/Cpp/gtk/_build/…/gtk/css/gtkcssenums.h” “D:/Coding/Cpp/gtk/_build/…/gtk/css/gtkcsserror.h” “D:/Coding/Cpp/gtk/_build/…/gtk/css/gtkcsslocation.h” “D:/Coding/Cpp/gtk/_build/…/gtk/css/gtkcsssection.h”
description = Generating$ gtk/css/gtkcssenumtypes.c$ with$ a$ custom$ command$ (wrapped$ by$ meson$ to$ capture$ output)

Now when I run “meson compile -C_build”, I don’t have the error anymore !

I still have a new error in the compilation but I will figure out why.
Thanks, it’s solved for me

1 Like

MSYS2 already has a pre-built GTK4. You can install that (via pacman -S gtk4 command). If you actually need to build GTK4 from source for some reason, you can take a look at the PKGBUILD file (the build script/manifest) they use in order to build GTK4. It contains the list of all the required build/runtime dependencies and the build & install commands that actually work in an MSYS2 environment.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.