How to use various compilers

From Freehackers
Jump to: navigation, search

Build tools


set env variables CC and CXX before starting cmake. Exemple with icc on gentoo using tcsh, starting from the project main dir:

 setenv CC /opt/intel/Compiler/11.1/056/bin/intel64/icc
 setenv CXX /opt/intel/Compiler/11.1/056/bin/intel64/icpc
 mkdir build && cd build
 cmake ..


Check which 'mkspec' you need by looking in $(QTDIR)/mkspecs/, and then use

 qmake -recursive -spec <specname>

The -recursive flag is great if your project was already configured with some other (default) spec file. Without it, only the main directory can be re-configured. Exemples on windows if you want to use the msvc2008 compiler.

 qmake -recursive -spec win32-msvc2008

Configuring for mingw32

 qmake -recursive -spec win32-g++

If you want to use clang with qt, see this blog entry.


Come on, this is ugly, old, and will doubtlessly create a lot of pain. Change your tools to something serious.



This is the default one on all linux distributions and most *BSD ones. Under windows, this is the compiler used by mingw32.

Testing gcc/g++ from last source (svn trunk, or using the mercurial mirror) requires to install the software. It's kind of possible to test it from the source using -B but it's painful.

MSVC 2008

Command line tools are available freely from MS site.


ICC can be downloaded and used under linux for non commercial usage. Beware that there is evidence that icc purposely generate bad code when it detects a non-intel cpu. But if you just want to check against icc C++ parser, you don't mind.


For c++, I highly suggest using the svn trunk. For C and objective-C, the latest official release is ok. i use CXX=~/svn/llvm/Release/bin/clang++ If you want to use clang with qt, see this blog entry.

Build tools with cross-compilation setup

You can find lot of good documentation on the net about cross-compilation. We just recall here that you'll need a local copy of the target's libraries you want to link to (you probably want headers, too). For example, we will suppose that the Qt (-4.6) directory for Windows is available under our unix filesystem under ~/cross-compiling/qt-4.6-windows


qmake does not support cross-compiling. You can find hacks with google (creating dedicated mkspec files), but this is not officially supported by Nokia/Trolltech. Cross compiling projects built with Qt can be tricky because you need some tools (moc,uic) on the host and you need to carefully check compatibility with the one on the target.


cmake is said to have 'good support for cross-compiling', but if you want to use Qt in a cross compilation environment, it wont work. See for example this mail on the official list.

The primary information can be found on the official cmake page about cross-compiling

Some useful hints might be found on the KDE technical knowledge base