I need to cross-compile GTK+ application from GNU/Linux (Arch Linux) to Windows. I have already tried to use mingw32
, but it does not see all libraries (including c's standard library!). So, I need to: find the standard libary; find all other (glib, gio, gtk, etc) libraries. But there's a problemm - I cannot find them. I also cannot compile from Windows. What must I do?
You can find the binaries for gtk 3 for windows on source forge or on http://win32builder.gnome.org/.
Once you have extracted them, you can follow this tutorial steps:
1) Install the compilation toolchain
Install the GCC compiler for Windows (namely MinGW, Arch Linux doc of package):
#pacman -S migw-w64
Download the latest all-in-one bundle ZIP archive directly from the official website (here's a direct link)
Adapt GTK+ to its location : In a terminal, move to the "gtk3-win32" folder you just created. For example: $cd /opt/gtk3-win32
then do :
find -name '*.pc' | while read pc; do sed -e "s@^prefix=.*@prefix=$PWD@" -i "$pc"; done
2) Compile
We will tell pkg-config
to locate GTK+3 libraries in our custom path. If you extracted to /opt/gtk3-win32
:
export PKG_CONFIG_PATH=/opt/gtk3-win32/lib/pkgconfig
We are ready to compile a sample C source ! Let's use a command in this style :
i586-mingw32msvc-gcc source.c -o executable.exe `pkg-config --cflags --libs gtk+-3.0
A new executable should have been created if everything went well. It won't run on our Linux system, because it's targeting Windows !
3) Release
Create a folder containing the binary and the Windows .dll files. If you extracted to /opt/gtk3-win32
:
mkdir ~/distri
cp executable.exe ~/distri
cp /opt/gtk3-win32/bin/*.dll ~/distri
Here we go ! Transfer this folder to a Windows box. Double-click on the executable and...
The following instructions are for gcc 5.3.0 (thread model: posix) and gtk+ 3.20.4
After installation, in msys2 shell
pacman -S mingw-w64-i686-gtk3
cd /mingw32
tar cfz c:/temp/mingw32.tar.gz
For gcc 5.3.0, edit /etc/pacman.conf
[core]
Server = https://archive.archlinux.org/repos/2016/05/10/$repo/os/$arch
[extra]
Server = https://archive.archlinux.org/repos/2016/05/10/$repo/os/$arch
[community]
Server = https://archive.archlinux.org/repos/2016/05/10/$repo/os/$arch
In case of upgrade
pacman -Syu
In case of downgrade
pacman -Syyuu
Later Arch Linux version seem to have gcc 6.1.1 that might be incompatible with msys2 gcc. A virtual machine might be a good idea for an Arch Linux installation that will not be upgraded (i.e. no security updates).
Unpack mingw32.tar.gz on linux, for example /opt/mingw32
perl -pi.bak -e 's,^prefix=.*,prefix=/opt/mingw32,' /opt/mingw32/lib/pkgconfig/*.pc
For example, before executing a configure script
export PKG_CONFIG_PATH=/opt/mingw32/lib/pkgconfig
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With