en fr

es pl

sv de
direct download download direct download

howto/en/cross-compile using mingw

From Wormux

MinGW is an environment to produce Windows binaries for both Linux and Windows. This documentation focuses mostly on the former OS, but checking any difference with the other Windows guide is advised.

Contents

Base system

Some, if not most, distributions ship pre-built mingw packages. For this reason, this documentation will not explain how to compile a cross-compiler: there are plenty of tutorials around the net on this particular topic.

One example of installation is (as root, or using sudo):

 # apt-get install mingw32 mingw32-binutils

In most situation, there will be a new hierarchy under /usr, named after your cross-compiler. This one can be for instance:

 /usr/i586-mingw32msvc

We will name this the "cross-compiler folder" from now on, with i586-mingw32msvc the host alias. If possible, it is suggested to do a symlink between this folder and /mingw:

 ln -s /usr/i586-mingw32msvc /mingw

There may also be binaries starting with the same value in /usr/bin, such as:

 /usr/bin/i586-mingw32msvc-gcc
 /usr/bin/i586-mingw32msvc-g++
 /usr/bin/i586-mingw32msvc-ld
 /usr/bin/i586-mingw32msvc-strip
 /usr/bin/i586-mingw32msvc-ranlib

and so on.

Side dependencies

In order to test the resulting game or fully pass the configure setup, you may want to install wine. It is no longer required, but if you choose to install wine, here is an example:

 apt-get install wine

Libraries

The .lib and .exp files are files used by Visual Studio, and are mostly located in lib/; they can be safely removed. The .dll are shared libraries, typically found in bin/; you shouldn't remove them, but instead make them available to your wine environment, as at least SDL.dll is needed by wine to run some of the programs the configure script creates. The Windows' system32 folder of your wine folder, or simply wormux folder, are a place where to put this dll.

Installing devel libraries: intermediate solution

Another solution is to run the win32 GTK+ installer with wine, and move the typical SysV hierarchy (bin/etc/include/lib/share) to your cross-compiler folder. Some other packages come as tarballs or zips, so use your favorite tool to unpack those archives and move their content to your cross-compiler folder.

Installing devel libraries: simplest solution

Storing on gna a tarball containing all of this stuff is a solution as, all software being GPL, this should not cause legal trouble. For now, you can get mine.

Fixing the environment

pkg-config is used to find package installation. However, you may have both the native and cross-compiling versions of some libs. Our configure script looks first for pkg-config whose name is prefixed with the host alias, then the normal pkg-config. One solution is to create a script, for instance i586-mingw32msvc-pkg-config:

 PKG_CONFIG_LIBDIR=/usr/i586-mingw32msvc/lib/pkgconfig \
 PKG_CONFIG_PATH=/usr/i586-mingw32msvc/lib/pkgconfig pkg-config $*

In addition, .la files found in lib/ and .pc files found in lib/pkgconfig/ may still point to incorrect locations. One way to fix the .pc files is to run:

 sed -i 's|^prefix=.*$|prefix=/usr/i586-mingw32msvc|g' lib/pkgconfig/*.pc

Last but not least, the cross-compiler, contrary to their native equivalent, have a weird bug whereby they do find the libraries to link bu mess up with the symbol match. One way to fix this is to rename all .lib files into lib.a:

 for f in *.lib; do mv $f lib${f%%lib}a; done

Running the configure script

You can simply run:

 ./configure --host=i586-mingw32msvc --with-sdl-prefix=/usr/i586-mingw32msvc --with-curl-prefix=/usr/i586-mingw32msvc --disable-sdltest

The --host option specifies what system the final program will run on. The --with-sdl-prefix command is used to avoid running a sdl-config pointing to an improper location and therefore not compatible with mingw. Finally, --disable-sdltest prevents configure from building and running a SDL test program, that fails if wine is not available.

Building an installer

As for mingw, make install is available. The actual names of sdl-config and pkg-config were hard-coded in here, so you may want to modify them at the top of tools/win32_setup/create_setup.sh, inside of the first test block.