C ++ Qt - How to add "-std = C ++ 11" to the makefile generated by qmake?

I am developing a program in Qt. Its makefile is automatically created from the .pro file. I need to use some code for which I need to set the -std = C ++ 11 flag for g ++. Where should this flag be added to .pro? (changing only the Makefile will not work, as it will be overwritten by the newly created one, every time I create a project).

+43
c ++ 11 qt makefile qmake
Oct. 16 '13 at 8:22
source share
5 answers

You can add the following to Qt.pro for C ++ 11: -

CONFIG += c++11 

As in Qt 5.4, C ++ 14 can be enabled with

 CONFIG += c++14 
+63
Oct 16 '13 at 8:25
source share

You can change the CXX flags:

 QMAKE_CXXFLAGS += -std=c++11 

I usually install it as:

 QMAKE_CXXFLAGS += -std=c++11 -Wall -Wextra -pedantic 
+19
Apr 11 '14 at 13:18
source share

You might want to insert a specific flag (which you mentioned)

 QMAKE_CXXFLAGS += -std=c++11 

in your .pro file, but this will enter exactly this flag on your behalf.

This is not enough. The correct way is to paste instead

 CONFIG += c++11 

in your .pro file. Then two or three necessary changes are made using qmake :

  • -std=c++11 .
  • -stdlib=libc++ .
  • If you are on a Mac, -mmacosx-version-min=10.6 becomes -mmacosx-version-min=10.7 . (Perhaps some of these changes are necessary for other operating systems or OS versions.)

(A similar problem is in 1 and 2. )

+11
May 12 '14 at 17:31
source share

I am using Snow Leopad 10.6.8 and gcc 4.9, I had to use

 CONFIG += c++11 

instead

 QMAKE_CXXFLAGS += -std=c++11 

The latter was simply not recognized.

+2
Jul 13 '15 at 19:33
source share
 CONFIG += c++11 

The .pro file works for me with the Qt4 SDK after installing qt5-default on the Ubuntu desktop:

 sudo apt install qt5-default 

In any case, the generated makefile contains the -std=c++0x parameter, which, I suspect, is sufficient to compile my C ++ 11 code.

0
Sep 09 '16 at 6:21
source share



All Articles