How to build distribution package for Windows

I’m a newbie of GTK3.

I wrote my first simple GTK3 app.
Everything work on Debian.

I also can successfully cross-compile from Debian to Windows using MXE [1], both dynamically linked and statically linked. Statically linked 64bit, generate a 18 MB stripped .exe and require only .glade file to work, no themes or external icons.

Now I’m trying to build that simple GTK app for Windows, using Windows and Mingw/MSYS2 as documented at [2]

MSYS2 is amazing as work really like Linux, Makefile and GNU toolchain, so generating a dynamic binary and collecting all the DLL is easy.

MinGW64 GTK3 version is 3.24.34

The dynamic 64bit binary is 128 kB, then I collected all the DLL reported by ‘ldd’ and are about 22 MB all stripped.

The resulting binary does not start as complaint with this error:

Gtk:ERROR:…/gtk/gtk/gtkiconhelper.c:494:ensure_surface_for_gicon: assertion failed (error == NULL): Failed to load C:\ProgramFiles\msys64\mingw64\share\icons\Adwaita\16x16/status\image-missing.png: U nrecognized image file format (gdk-pixbuf-error-quark, 3) Bail out! Gtk:ERROR:…/gtk/gtk/gtkiconhelper.c:494:ensure_surface_for_gicon: assertion failed (error == NULL): Failed to load C:\ProgramFiles\msys64\mingw64\share\icons\Adwaita\16x16/status\image-miss ing.png: Unrecognized image file format (gdk-pixbuf-error-quark, 3)

I tryed to follow the steps “Building and distributing your application” at [2] but some are not clear.

Step 1: OK
Step 2: is not clear where copy the "Adwaita" directory, I put to <appDir>/share/icons/Adwaita
Step 3: there are no icons in hicolor package, I copyed the one from:
Step 4: OK
Step 5: I had to manually create the dir:
or I got missing directory error.
Then I got always this:
<appDir>$ glib-compile-schemas share/glib-2.0/schemas
No schema files found: doing nothing.

The binary still does not start as complaint with the same error as above.

What other I have to do?

Is there an updated how to for generating a native Win binary?

thank you

[2] The GTK Project - A free and open-source cross-platform widget toolkit

no one build GTK3 apps on Windows using MinGw/MSYS2 ?
Note: running GTK2 apps built with the same toolchain, work well

You have to be patient: you are not owed a reply, and people will answer your questions when they are able to do so, on their own time.

I understand.
It just seemed strange to me that no one else has had this problem with Windows, following the official instructions on the site. Will wait till some hints, thank you

Hi! See Convert GTK4 project to exe without need to install on GTK4 on customer client. That should get you going, let us know of any issue you encounter!

will try, and will give feedback, thank you!

1 Like

OK, work.
I had to add only the .glade file copy that is missing in the linked app.

The script by taozuhong(taozuhong (Tao Zuhong) · GitHub) create a 207 MB bundle, that, for a base app that shows 10 widgets (see attached .glade GUI description), it seems to me frankly excessive.
I will check what is really necessary and report here. (52.7 KB)

Make sure you’re not bundling the entire Adwaita icon theme; you should bundle the icons your application needs.

$ du -chs *
42M bin
5,0K etc
1,1M lib
185M share
228M totale

share$ du -chs *
8,0K doc
60K glib-2.0
2,7M gtksourceview-4
37M icons
146M locale
6,0K themes
185M totale

mostly are locales, about 3 MB per language, and my app will not be localized.
Second are icons. As now my app do not use icons.

I’d say you could drop all the languages you don’t need. GTK has a lot of localised strings for the UI, especially for complex widgets like the file selection and print dialogs.

GTK should ship its own assets, but things like file type icons will still be needed.

Incidentally, I would recommend using GTK4 instead of GTK3; GTK4 dropped a lot of unnecessarily localised strings, and it definitely ships its own icon assets, so you would not necessarily need the icon theme.

about GTK4, I evaluated to write the GUI for my basic app in GTK3 or GTK4 past week, but them I saw that:

  1. my Debian 11 repo do not include GTK4, so I had to compile myself from sources, and it is difficult.
    I made only once with GTK2, cross-compiling with osxcross to generate a package with Quartz backend for macOS (prebuilt lib from macports supplied by osxcross use XQuartz that require macOS user to install an Xserver, not a pleasure). Was cumbersome.
  2. as today osxcross do not support GTK4

So, as my need is to generate a cross-platform GUI app, as today I will use GTK3, and when GTK4 are more supported I think I can easily switch to GTK4.

I think the page at The GTK Project - A free and open-source cross-platform widget toolkit must be updated, it is not complete, out of date and misleading. Urgent update

The page is definitely not out of date: it’s pretty much what we do in our CI infrastructure.

The wording can definitely be improved; if you have suggestions, feel free to edit this file: and open a merge request with your changes.

the part to help configure and build with MSYS is well done. It is the part to deploy the Win package that miss some parts and it is not clear. Will propose an update

Thanks, that’s very much appreciated.

Building GTK4 on a native toolchain is definitely easier: you don’t need anything more than cloning the GTK repository and then Meson will download, configure, and build all the dependencies. We don’t have that for GTK3.

some of the difficulties I encountered compiling the GTK2s for Quartz:
) GLIB’s configure is missing
use Meson / Ninja as build system instead of Automake / Make
) error on GLIB build ???
use Meson backports v0.56.1
) pixman-0.34.0: utils-prng.c: 207: 27: error: use of unknown builtin ‘__builtin_shuffle’
switch to pixman-0.36.0
) switched to libpng16 v1.6.27 the only one available from:
) ATK’s configure: error: *** GLIB 2.31.2 or better is required
export PKG_CONFIG = / usr / bin / pkg-config
use pkgconf (v1.7.3 ) instead of pkg-config 0.29
) cairo’s configure: error: recommended PNG functions feature could not be enabled
copy zlib.pc from in $ PREFIX / lib / pkgconfig
) cannot run test program while cross compiling
change “as_fn_error” to “echo” in gdk-pixbuf’s configure
) gdkaliasdef.c: 220: 102: error: aliases are not supported on darwin
add --disable-visibility to GTK’s configure

In the mean time, well that MSYS2 already has gtk4 4.8.1-1

GTK2 is EOL, so building it in 2022 is not only not recommended but actively discouraged.

this is why I switched to GTK3.

Update: I saw that the only really needed files for my app built with MinGW/MSYS2 to work are:


so are about 23 MB

While adding:


will avoid one WARN:

(resolveGui_mingw64.exe:13252): Gtk-WARNING **: 17:47:30.276: Could not load a pixbuf from /org/gtk/libgtk/theme/Adwaita/assets/bullet-symbolic.svg.
This may indicate that pixbuf loaders or the mime database could not be found.

Anyway three other GDK WARN remain, only on one of my target (maybe it is the only one with a custom keyboard layout to let type Linux extended compose keys on Windows). Let’s check:

(resolveGui_mingw64.exe:13252): Gdk-WARNING **: 17:47:30.022: Could not open registry key 'SYSTEM\CurrentControlSet\Control\Keyboard Layouts\00090410'. Error code: 2

(resolveGui_mingw64.exe:13252): Gdk-WARNING **: 17:47:30.029: Could not open registry key 'SYSTEM\CurrentControlSet\Control\Keyboard Layouts\(NULL)'. Error code: 2

(resolveGui_mingw64.exe:13252): Gdk-WARNING **: 17:47:30.029: Failed to load keyboard layout DLL for layout 00090410: (NULL)

I will eventually try to cross-build a GTK3 stack and all deps with them hybrid toolchain targeting Quartz, after all I need to bring my GTK3 app to macOS as well, and should be a similar trouble than GTK2

Building GTK4 natively on macOS is done in the same way as on Windows: use Meson to download, configure, and build all the dependencies. That’s one of the reasons we use Meson as the build system.

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