Gentoo Wiki



Build a Windows binary with MinGW and Qt4 on Linux


(If you experience problems, try and use the same version qt for both installs)

Install linux QT4

emerge qt


emerge =x11-libs/qt-<version>

to install specific version

Install Windows Qt4

Download QT4 windows files. Either install on windows, or using wine (Tested with wine-1.0-rc3). Ignore the prompt to specify location of mingw installation or download it, and tell it to continue anyway.

Installing crossdev toolchain

A complete guide is available at HOWTO MinGW.

Minimal instructions:

emerge crossdev
crossdev -t i686-pc-mingw32

Once mingw is installed, test by compiling some example programs in MinGW's Documentation.

Copying windows libraries

Crossdev installs the mingw compiler in /usr/i686-pc-mingw32. Copy the contents of /Qt/<version> (bin, lib, include etc.) into /usr/i686-pc-mingw32/Qt. (You may copy them anywhere else, and make the necessary modifications to the next section)

Changing qmake default (mkspecs)

qmake can use some files to specify defaults for the build environment. On gentoo these files are located at /usr/share/qt4/mkspecs. The one that we are interested in is win32-g++. The following modifications are needed to make qmake aware of the corssdev toolchain:


QMAKE_CC              = i686-pc-mingw32-gcc
QMAKE_CXX             = i686-pc-mingw32-g++
QMAKE_INCDIR_QT               = /usr/i686-pc-mingw32/Qt/include
QMAKE_LIBDIR_QT               = /usr/i686-pc-mingw32/Qt/lib
QMAKE_LINK            = i686-pc-mingw32-g++
      QMAKE_COPY_DIR          = cp -r
      QMAKE_COPY              = cp
      QMAKE_DEL_FILE          = rm
QMAKE_MOC             = $$[QT_INSTALL_BINS]/moc
QMAKE_UIC             = $$[QT_INSTALL_BINS]/uic
QMAKE_LIB             = i686-pc-mingw32-ar -ru
QMAKE_RC              = i686-pc-mingw32-windres

Note: There is more than one copy of some symbols, such as QMAKE_COPY_DIR

Compiling windows executable

Changes to qmake .pro files

The defaults for qmake for linux and win32 toolchains are different. To avoid problems, add

CONFIG -= debug_and_release_target

too all the .pro files in your project. This solves the problem of qmake building makefiles which place object files into ./release and ./debug folders instead of the root of the source files folder.



qmake -spec win32-g++ 

instead of


In case of problems try adding -recursive to the qmake command line.

Running the Application

Missing .dll files can be found in QTINSTALLDIR/bin and /usr/i686-pc-mingw32/usr/bin. Missing SQL plugin dlls should be placed in a folder under the one containing the compiled executable called sqldrivers.

See also

Bold text

Retrieved from ""

Last modified: Sun, 21 Sep 2008 06:06:00 +0000 Hits: 6,295