New GTK+-3.15.4.0 for Windows 64-bit

Update. Windows binaries of GTK+-3.14.0, gstreamer-1.4.4, Python3, pygtk3 gobject-introspection PyGObject (aka PyGI) are available from here, so this guide is not necessary (unless the latest version of GTK+ without PyGI is desired)

We recently cross-compiled GTK+ from Fedora Linux x86_64 to the Windows 64-bit target using the mingw64 compiler. We tested it on wine (video clip on the upper-right of the page). It was an adventure getting all the prerequisites to build, but it results in an stripped-down version of GTK+ without PyGI. (PyGI can not currently be compiled on Linux.)

Fedora Packages

"You will need to get the GLib, Cairo, Pango, ATK, and GTK+ developer packages to build against GTK+. To run GTK+ programs you will also need the libpng and zlib packages, and if your code uses gettext for internationalization and/or you want GTK+ internationalization, the gettext package." www.gtk.org/download/win64.php

Installing packages is the only time you will need root permissions in this entire guide. Besides these packages you may wish to install autojump for getting around.

sudo yum -y install git hg wine autoconf-archive
mingw64-gstreamer-plugins-base mingw64-crt mingw64-adwaita-icon-theme mingw64-pixman mingw64-libgcrypt 
mingw64-gtkspell3 mingw64-zlib mingw64-atk mingw64-libxml2 mingw64-gstreamer-plugins-good mingw64-libogg 
mingw64-libgnurx mingw64-fontconfig mingw64-wine-gecko mingw64-filesystem mingw64-libgpg-error mingw64-p11-kit 
mingw64-enchant mingw64-libvorbis mingw64-cpp mingw64-openssl mingw64-libglade2 mingw64-sqlite mingw64-libpng 
mingw64-expat mingw64-hicolor-icon-theme mingw64-gettext mingw64-ilmbase mingw64-opus mingw64-readline 
mingw64-win-iconv mingw64-headers mingw64-termcap mingw64-gcc-c++ mingw64-icu mingw64-gnutls mingw64-wavpack 
mingw64-glib2 mingw64-gtk3 mingw64-libtasn1 mingw64-binutils mingw64-freetype mingw64-gmp mingw64-cairo mingw64-jasper 
mingw64-xz-libs mingw64-gstreamer-plugins-bad-free mingw64-libffi mingw64-bzip2 mingw64-libltdl mingw64-gsm 
mingw64-gdk-pixbuf mingw64-SDL mingw64-nettle mingw64-libsoup mingw64-pkg-config mingw64-libtiff mingw64-harfbuzz 
mingw64-hunspell mingw64-gstreamer mingw64-winpthreads mingw64-gcc mingw64-OpenEXR mingw64-orc
mingw64-libjpeg-turbo

Environment

This assumes or sets up a 64-bit .wine target (host) directory with the required cross-build flags.

mingw64-env
export BUILDDIR=$HOME/dev/win_64/gtk #dir containing all the download folders
export MINGW=/usr/x86_64-w64-mingw32/sys-root/mingw
export GTK="$HOME/.wine/drive_c/gtk"
export PKG_CONFIG_PATH="$GTK/lib/pkgconfig:$MINGW/lib/pkgconfig"
export LDFLAGS=-L"$GTK/lib -L$MINGW/lib"
export CFLAGS="-mthreads -pthread -D_WIN32_WINNT=0x0501 -DWINVER=0x0501 -DG_OS_WIN32 -I$GTK/include"

export OPTS="--build=x86_64-redhat-linux-gnu --host=x86_64-w64-mingw32 --sysconfdir="$GTK/etc" --prefix="$GTK" \
--exec-prefix="$GTK"  --bindir="$GTK/bin" --libdir="$GTK/lib" --libexecdir="$GTK/libexec" --sbindir="$GTK/sbin" \
--sharedstatedir="$GTK/lib" --datarootdir="$GTK/share" --datadir="$GTK/share" --includedir="$GTK/include" \
--infodir="$GTK/share/info" --mandir="$GTK/share/man" --localstatedir="$GTK/var" --disable-static"

-D_WIN32_WINNT=0x0501 -DWINVER=0x0501 flags specify Windows XP or greater.

Download these dependency sources. This is the order in which we built them successfully.

git clone git://git.gnome.org/glib
git clone git://git.gnome.org/atk
zlib //zlib.net/
libpng https://libpng.sourceforge.net/index.html
git clone git://git.gnome.org/gdk-pixbuf
git clone git://anongit.freedesktop.org/git/pixman
git clone git://anongit.freedesktop.org/git/cairo
git clone git://git.gnome.org/pango
git clone https://github.com/anholt/libepoxy.git
git clone git://git.gnome.org/gtk+

Reading

Notice: Do not use root or sudo administrator permissions for any of the make install steps. This howto installs them to the default .wine folder in the user's $HOME directory, which should not require any special permissions. Do not use root or sudo to run wine, nor to do any tests. That's now how any of this works. As a matter of fact, it would be better to log in as an unpriviliged dev user, or chroot sandbox.

This is just a temporary test build walkthrough. Of course there are no guarantees, but if followed correctly, no changes should happen to anything on the Linux development platform. For something more permanant, you could go ahead and re-compile some of these dependencies into Linux's Mingw64 itself from a different shell, and using mingw64-make but that is beyond the scope of this particular agenda.

About these dependencies www.gtk.org/download/win64.php

Detecting mingw compiler macros sourceforge.net/p/mingw-w64/discussion/723798/thread/ea355c1f/

Cross-compiling Glib

Make sure to run mingw64-env and have the above environment variables defined.

git pull
./autogen.sh "$OPTS" --disable-gtk-doc --enable-shared
automake --add-missing
autoconf
./configure $OPTS --disable-glibtest
make -j24
make install #no sudo!
cd ..

On fail: Get our glib.patch.

cd glib
patch -p0 < ../glib.patch
less README.win32

If Glib or Atk gives an error about Makefile.in.in being missing:

gedit po/Makefile.in.in #add blank targets all: clean: install:
touch tests/Makefile.in
touch docs/Makefile.in
touch gtk-doc.make

Cross-compiling Atk

cd atk
git pull
./autogen.sh "$OPTS"  --disable-glibtest
automake --add-missing
autoconf
./configure $OPTS --disable-glibtest
make -j24
make install #no sudo!
cd ..

On fail: Get our atk.patch

patch -p0 < ../atk.patch

Cross-compiling Zlib

./configure --prefix=$HOME/.wine/drive_c/gtk --eprefix=$HOME/.wine/drive_c/gtk --64 \
--libdir=$HOME/.wine/drive_c/gtk/lib  --includedir=$HOME/.wine/drive_c/gtk/include
make -j24
make install #no sudo!
cd ..

If you get an error like "cannot find -lc" Remove -lc from the last build command and re-run it. I mean select the whole multiline blob starting with x86_64-mingw64-gcc ... blah blah -lc -lblah -o blah. Paste it back into the terminal without the -lc. We don't know what macro it came from, and it's quicker than fixing the project, but somebody should submit a patch...

Cross-compiling Libpng

mv code libpng
cd libpng
automake --add-missing
autoreconf
make -j24
make install #no sudo!
cd ..

Cross-compiling Gdk-pixbuf

cd gdk-pixbuf
./autogen.sh $OPTS
make -j24
cd tests
wine ../gdk-pixbuf/gdk-pixbuf-query-loaders > ../gdk-pixbuf/loaders.cache
make -i
make -i install #no sudo!
cd ..

Tests would not build, and disabling them didn't work, so we just forced the whole thing with make -i. Terrible!

Cross-compiling Pixman

cd pixman
./autogen.sh $OPTS
make -j24
make install #no sudo!
cd ..

Cross-compiling Cairo

cd cairo
./autogen.sh $OPTS
make -j24
make install #no sudo!
cd ..

Cross-compiling Pango

cd pango
./autogen.sh $OPTS
make -j24
make install #no sudo!
cd ..

Cross-compiling Epoxy

cd libepoxy
./autogen.sh $OPTS
make -j24
make install #no sudo!
cd ..

Cross-compiling Gtk+

cd gtk+
./autogen.sh $OPTS --disable-cups
make -j24
make install #no sudo!
cd

Testing on Wine

Add to "GTKDIR" to .wine/system.reg and add %GTKDIR%\\bin to "PATH"

"GTKDIR"="C:\\gtk" 
"PATH"=str(2):"C:\\Python27\\;C:\\Python27\\Scripts;C:\\windows\\system32;C:\\windows;C:\\windows\\sys
tem32\\wbem;%GTKDIR%\\bin"

Configure fonts according to www.gtk.org/download/win32_tutorial.php

wine cmd
pango-querymodules > %GTKDIR%\etc\pango\pango.modules
gdk-pixbuf-query-loaders > %GTKDIR%\lib\gdk-pixbuf-2.0\2.10.0\loaders.cache
gtk-query-immodules-3.0 > %GTKDIR%\lib\gtk-3.0\3.0.0\immodules.cache

Launch test after installing icon theme from mingw. You could also try it before doing all these steps and then spend all day searching around trying to fix it like we did. It'll look interesting. :)

cd .wine/drive_c/gtk/bin
ln -fs /usr/i686-w64-mingw32/sys-root/mingw/share/icons/Adwaita ../share/icons/
ls gtk*
wine gtk3-demo.exe

Roadmap: Where do we go from here?

todo: Set up a Windows box and build gobject-introspection and rebuild GTK+ on Windows.
todo: Try to get Python 2.7 working with gobject-introspection, gst-1.0, and GTK-3.15.4 also on Windows.
todo: OpenGL is supposed to work for X11 (Linux) and Wayland (Windows?) using libepoxy. We need to find out why GTK+ didn't build Wayland. The files are there. Either a configuration option was missed, or a dependency is needed, either gtkglarea2, or maybe gtkglext for OpenGL tests to work. It's not a high priority because our apps don't use OpenGL right now, but it could accelerate rendering.

Rapid Application Development with Glade 3.0 part 1 GTK+ interfaces
Rapid Application Development with Glade 3.0 part 2 Python example
Rapid Application Development with Glade 3.0 part 3 GTK+ and C Programming


CCBY Copyright © 2024 Henry Kroll III, thenerdshow.com This web page is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.