Silmor . de
Site Links:
Impressum / Publisher

Cross compiling Qt/Win Apps on Linux

Important note: this how-to is written for Qt 4.x - it should work for both the commercial and the free versions (I tested it with commercial).

In order to run these tests you'll need a cross compiler. How to create one is described in Part 1 of this series.

If you want to use this for a commercial (non-GPL) project, you have to make sure you own the right licenses. According to Trolltech's support you need one for each developer on the platforms he/she actually develops on and at least one for each target platform - so that you can link against the correct runtime libs. Eg. if you have three developers, two working on Linux and one on Windows and your target platforms are Linux, Windows, and MacOS/X then you will need four licenses: one for each developer (twice X11, once Win32) and an extra one for the additional target platform MacOS/X.

Preparing Qt

You have two options of building Qt:

Then build the same version of Qt for Linux - you will need the tools (qmake, uic, moc, etc.).

You will need the include and library files of Qt for compiling and linking, so if you built Qt on Windows: either mount the Windows disk on Linux or copy the full tree over to your Linux disk. It is not recommended to mix the directories.

On your Linux copy of Qt go into the mkspecs directory and copy the win32-g++ spec to win32-x-g++ and correct the qmake.conf file - you'll find an example for 4.0.1 in win32-x-g++-qmake.conf.

The important part is to replace all references to gcc/g++ with references to the cross compiler and to replace the cmd.exe shell utilities with their Linux counterparts.

Also make sure "-mwindows" is in the spec otherwise you will be bothered with a console window snapping open everytime a Qt-App starts (replace that with "-mconsole" if you actually plan to create console apps).

These are the important lines for an installation that has MinGW in /usr/local/mingw and Qt/Win in /usr/local/Trolltech/Qt-Win-4.0.1:

QMAKE_CXX		= /usr/local/mingw/bin/i586-mingw32-g++

QMAKE_INCDIR		= /usr/local/mingw/include
QMAKE_INCDIR_QT		= /usr/local/Trolltech/Qt-Win-4.0.1/include
QMAKE_LIBDIR_QT		= /usr/local/Trolltech/Qt-Win-4.0.1/lib

QMAKE_LINK		= /usr/local/mingw/bin/i586-mingw32-g++
QMAKE_LFLAGS		= -mthreads -Wl,-enable-stdcall-fixup -Wl,-enable-auto-import \
   -Wl,-enable-runtime-pseudo-reloc -mwindows

QMAKE_MKDIR		= mkdir -p
QMAKE_DEL_DIR		= rm -rf

QMAKE_RC		= /usr/local/mingw/bin/i586-mingw32-windres

QMAKE_ZIP		= zip -r -9

QMAKE_STRIP		= /usr/local/mingw/i586-mingw32-strip


Call QMake with the new cross-compile spec (qmake -spec win32-x-g++), then it will set the remainder automagically. You even don't need to set PATH if the spec contains absolute paths to the MinGW cross compiler.

Left to be wished is of course welcome: please send suggestions to konrad at silmor dot de.

Webmaster: webmaster AT silmor DOT de