Aug
23
Cross-compiling a Qt win32 app on Linux
Filed Under (Coding, Compilers, Linux, Open source) by 2of1 on 23-08-2010
I’ve been looking for a way to compile an app developed with Qt Creator on Linux for Windows.
I came across this but I needed to tweak it before it worked so I decided to blog my own mini-guide (tested working with with Qt 4.6.3).
This assumes that you already have the Qt SDK (for Linux) installed.
- The first thing to do is download and install the MinGW cross compiler
- Then download the Windows version of the Qt SDK. As it’s distributed as a Win package, you’ll need to either install it on windows and copy the necessary files across to your linux distro (what I did) or install it through Wine (not sure if this even works). You can cross-compile it as well if you’re being adventurous
- Place the Qt Win SDK libraries in /usr/lib32/qt4win32 and headers in /usr/include/qt4win32
- Copy /usr/share/qt4/mkspecs/win32-g++/ to /usr/share/qt4/win32-x-g++/
- In the above directory, replace qmake.conf with the one found here
- Make sure that the paths in qmake.conf match those of your system (see NOTE below); specifically QMAKE_CXX, QMAKE_LINK, QMAKE_INCDIR, QMAKE_INCDIR_QT, QMAKE_LIBDIR_QT
- Run qmake adding –spec win32-x-g++ command line arg. This should cross-compile your app.
NOTE: As my linux box is a x86_64, my /usr/lib is /usr/lib32. Please adjust this accordingly for your setup.




This works great on Kubuntu 10.10 with Qt4.7.0 and mingw installed from the repos. Only thing I would add is that it is essential that the win32 and linux Qt’s match exactly.
Here (http://blog.kermat.net/blog5.php/cross-compilation-with-qt) you can find a complete tutorial to set up a cross-compilation environment with Qt. There is also a downloadable script that automates the installation. Tested with Qt 4.7.2.