Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save RickBarretto/8c90ad46a88257b2062b17a8cbe65b86 to your computer and use it in GitHub Desktop.
Save RickBarretto/8c90ad46a88257b2062b17a8cbe65b86 to your computer and use it in GitHub Desktop.
An easy way to distribute GTK applications and dependenices on Windows

Distribute GTK Apps with Windows (MSYS2)

Make sure package mingw-w64-x86_64-gtk4 is installed. Build your project with a custom prefix (e.g. ~/my-gtk-app-prefix). Navigate to this directory such that you have subdirectories 'bin', 'lib', 'share', etc containing the executable to distribute.

If you want to compile with Adwaita, please check if the package mingw-w64-x86_64-libadwaita is installed. 😉

1. Dependent DLLs

The following command copies all dependent DLLs to the current directory:

$ ldd ./bin/mygtkapp.exe | grep '\/mingw.*\.dll' -o | xargs -I{} cp "{}" ./bin

Where mygtkapp.exe is the executable in question (e.g. gtk3-demo, etc). This ensures that the necessary DLLs are bundled in the application folder so the end user does not need their own installation of msys2.

All credit to: https://stackoverflow.com/a/50130668

2. GdkPixbuf Loaders

GTK will crash if it cannot load images. GdkPixbuf needs various loaders for different image formats. Your prebuilt loaders will suffice.

Copy them over to the custom prefix directory:

cp -r /mingw64/lib/gdk-pixbuf-2.0 ./bin/lib/gdk-pixbuf-2.0

3. Icon Theme

We then need to copy over the Adwaita and hicolor icon themes, otherwise GTK will display a fallback 'missing icon' symbol.

$ cp -r /mingw64/share/icons/* ./bin/share/icons/

4. Schemas

The relevant settings schemas need to be installed. Copy them over and recompile. You may want to manually inspect the copied over schemas (in case unrelated projects are also copied).

$ cp /mingw64/share/glib-2.0/schemas/* ./bin/share/glib-2.0/schemas/
$ glib-compile-schemas.exe ./bin/share/glib-2.0/schemas/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment