The cross compilation of gobject-introspection from linux to mingw has been proven a really tough task. That project seems an octopus connected at runtime to different part of the system: python, pkg-config, a shell, dlltool and cc. On a standard unix based system all those tools are already installed but when cross-compiling you must build every single piece by yourself.

My first approach was to build everything on the host side (i.e. on mingw-w64). I still think this is the correct way (after all I need to add introspection for packages installed on the host side) but after a lot of trial and error (more errors than trials) I gave up. I was bound continuosly from the build side to the host side and vice versa because of path format, filename mangling and requirements. When I realized I had to build gcc on the host I was fed up. I just tried a precompiled binary and definitively gave up after the umpteenth error.

The second approach was to leverage the tools on the build system by configuring them to work with the paths of the host system. It was not straight-forward but surely much easier than the previous attempt and, above all, successful!

The main problem was to build the giscanner python module for the build platform. I resolved building the project twice, as already done by Nicolas Dufresne when cross-compiling for other arch. I then leveraged wine to run host programs on the build side.

The changes on gobject-introspection are relatively few and unobtrusive. They can be pulled from my xbuild branch.

The build is still not as straight-forward as I would. I used a variation of the following (untested) procedure.

export CC=$arch-gcc
export PKG_CONFIG=$arch-pkg-config
export DLLTOOL=$arch-dlltool
export PYTHON=/usr/bin/python2
export GI_OS_NAME=nt
export INTROSPECTION_LAUNCHER="/usr/bin/env WINEARCH=win$bits WINEPREFIX=$srcdir/win$bits DISPLAY= /usr/bin/wine"
export XDG_DATA_DIRS="/usr/$arch/share:$XDG_DATA_DIRS"
export GI_TYPELIB_PATH="/usr/$arch/lib/girepository-1.0:$GI_TYPELIB_PATH"

# First pass: build the giscanner Python module with build == host
./configure \
    --disable-silent-rules \
    --enable-shared \
make scannerparser.c _giscanner.la

# Second pass: build everything else with build != host (i.e. cross-compile)
./configure \
  --build=... \
  --host=... \
  --prefix=... \
  --disable-silent-rules \
  --enable-shared \
  --enable-static \
  --disable-doctool \

# Avoid overriding what built in the first pass
make -t scannerparser.c _giscanner.la


In the real world I built the project on ArchLinux as part of a toolchain for cross-compiling GTK+2 and GTK+3 applications. The build script can be browsed on its dedicated PKGBUILD.

Post your comment


No one has commented on this page yet.

RSS feed for comments on this page RSS feed for all comments