Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C: GTK+ 3.0 (3.20) - Cross-Compile from GNU/Linux (Arch Linux) to Windows

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?

like image 790
handicraftsman Avatar asked Jun 10 '16 10:06

handicraftsman


2 Answers

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...

like image 116
Jacques Gaudin Avatar answered Sep 19 '22 09:09

Jacques Gaudin


The following instructions are for gcc 5.3.0 (thread model: posix) and gtk+ 3.20.4

Install msys2 on windows

Install gtk3 files and copy the files

After installation, in msys2 shell

pacman -S mingw-w64-i686-gtk3

cd /mingw32
tar cfz c:/temp/mingw32.tar.gz

Ensure matching gcc version on Arch Linux

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).

Copy files to linux

Unpack mingw32.tar.gz on linux, for example /opt/mingw32

Modify pkg-config files

perl -pi.bak -e 's,^prefix=.*,prefix=/opt/mingw32,' /opt/mingw32/lib/pkgconfig/*.pc

Set PKG_CONFIG_PATH

For example, before executing a configure script

export PKG_CONFIG_PATH=/opt/mingw32/lib/pkgconfig
like image 43
J.J. Hakala Avatar answered Sep 19 '22 09:09

J.J. Hakala