How do I configure Qt for cross-compilation from Linux to Windows target?

Just use M cross environment (MXE). It takes the pain out of the whole process:

  • Get it:

    $ git clone https://github.com/mxe/mxe.git
    
  • Install build dependencies

  • Build Qt for Windows, its dependencies, and the cross-build tools;
    this will take about an hour on a fast machine with decent internet access;
    the download is about 500MB:

    $ cd mxe && make qt
    
  • Go to the directory of your app and add the cross-build tools to the PATH environment variable:

    $ export PATH=<mxe root>/usr/bin:$PATH
    
  • Run the Qt Makefile generator tool then build:

    $ <mxe root>/usr/i686-pc-mingw32/qt/bin/qmake && make
    
  • You should find the binary in the ./release directory:

    $ wine release/foo.exe
    

Some notes:

  • Use the master branch of the MXE repository; it appears to get a lot more love from the development team.

  • The output is a 32-bit static binary, which will work well on 64-bit Windows.

Leave a Comment