Configuring the GCC compiler switches in Qt, QtCreator, and QMake

andand picture andand · Jun 7, 2010 · Viewed 76.4k times · Source

I recently tried to use Qt Creator 1.3.2, Qt 4.6.2, and GCC 4.4.0 (32-bit version) on Windows 7 (64-bit) to compile an application using some of the experimental C++0x extensions and encountered the following (fatal) error:

This file requires compiler and library support for the upcoming ISO C++ standard, C++0x. This support is currently experimental, and must be enabled with the -std=c++0x or -std=gnu++0x compiler options.

In my search for a solution, I came across the thread qmake and compiler flags?, and added the following to the .pro file:

CXXFLAGS += -std=c++0x

but that didn't seem to make a difference.

So, I expect there's some tag I need to add to the .pro (project) file, but I've never messed with the GCC compiler switches in Qt, QMake, and QtCreator before, and I am uncertain about the proper invokation / incantation. So, my question is how do you set GCC compiler switches when using QtCreator, QMake, and Qt?

Answer

andand picture andand · Jun 15, 2010

It boils down to reading the manual. Instead of using CXXFLAGS in the .pro file, you need to use QMAKE_CXXFLAGS as in:

main.cpp:

#include <cinttypes>

int main() { return 0; }

main.pro:

SOURCES += main.cpp
QMAKE_CXXFLAGS += -std=c++0x