[Interest] How best to turn on "-std=gnu++11" when using qmake to build a project?

Koehne Kai Kai.Koehne at digia.com
Wed Apr 17 08:50:20 CEST 2013



> -----Original Message-----
> From: interest-bounces+kai.koehne=digia.com at qt-project.org
> [mailto:interest-bounces+kai.koehne=digia.com at qt-project.org] On Behalf
> Of K. Frank
> Sent: Wednesday, April 17, 2013 12:18 AM
> To: Qt-interest
> Subject: [Interest] How best to turn on "-std=gnu++11" when using qmake
> to build a project?
> 
> Hello List!
> 
> When I am using qmake to build a project that uses Qt, what is the best way
> to turn on the compiler flag "-std=gnu++11"?  (I am using a mingw-w64 build
> of g++ 4.8.1.)

qmake -r QMAKE_CXXFLAGS+=-std=gnu++11

> Ideally, I would like to do this on a "global" basis, and not have to do it for
> each project separately (but that's not essential).

I'd personally advise against using any kind of magic here, just pass it to qmake explicitly.

If you really want to go down this route, you could also create a custom mkspec (say linux-g++-c++11) under mkspecs by copying your default one, and adding QMAKE_CXXFLAGS+=-std=gnu++11 to linux-g++-c++11/qmake.conf. You could then set the QMAKESPEC environment variable to $QTDIR/mkspecs/linux-g++-c++11. Anyhow, the next time you get 'weird' errors you better remember the magic :)

Finally, how about switching to Qt 5 ? Qt 5 is compiled with c++11 enabled by default, and you can enable it for your own projects by doing CONFIG+=c++11 (qmake based projects).

Regards

Kai




More information about the Interest mailing list