Silmor . de
Site Links:
Impressum / Publisher

Building a Cross compiler for Windows on Linux

This is a small How-To on creating a cross compiler for Windows that runs on Linux.


Why would one ever do something as stupid as compiling Qt/Windows applications on Linux? There are several (good and better) reasons to do this:

This article will show you how to create an environment on Linux, so that you don't need to leave it for compiling Windows applications. Unfortunately you'll still need Windows to test these applications.

Getting the sources

If you installed Qt/Win32 with MinGW before, just copy the MinGW source files (c:\MinGW\src\*.gz) from Windows to Linux.

Otherwise download the source packages from:, you'll need these packages (the versions in parenteses are the current ones I tested with, newer ones should work as well):

Creating the MinGW cross-compiler

It is assumed that:

  1. Unpack all archives
  2. compile binutils:
    ./configure --target=$TARGET --prefix=$PREFIX
    make && make install
  3. Copy the header files to the target:
    mkdir -vp $PREFIX/include
    cp -r mingw-runtime-*/include/* $PREFIX/include
    cp -r w32api-*/include/* $PREFIX/include
  4. Compile GCC for C only (you need C for the libs and the libs for C++):
    ./configure --prefix=$PREFIX --target=$TARGET --enable-threads --enable-languages=c
    make && make install
  5. Compile the Windows API:
    ./configure --prefix=$PREFIX --target=$TARGET --host=$TARGET --build=$(./config.guess)
    make && make install
  6. Compile the Windows Runtime:
    mv w32api-* w32api
    cd mingw-runtime*
    ./configure --prefix=$PREFIX --target=$TARGET --host=$TARGET --build=$(./config.guess)
    make && make install
  7. Re-compile GCC for C & C++:
    ./configure --prefix=$PREFIX --target=$TARGET --enable-threads --enable-languages=c,c++
    make && make install

It might happen that GCC has problems with linking, the solution is easy:

The install scripts create $PREFIX/lib and $PREFIX/$TARGET/lib - move everything from $PREFIX/$TARGET/lib to $PREFIX/lib and then make the former a link to the latter:
rmdir lib
ln -s ../lib lib

How to proceed

From there on you can use the MinGW C/C++ compiler just like any other version of GCC.

In Part 2 of this article I will explain how to cross compile Qt4/Win32.

In Part 3 I will explain how to compile Qt applications using this cross compiler.

Webmaster: webmaster AT silmor DOT de