简体   繁体   中英

Compilation of C++14 in qtcreator

I have a qt project containing parts in C++14 .

Recently, I changed my ubuntu distro. Now I have 16.04 LTS and I installed Qt creator 4.02 (built on jun 13).

In order to enable C++14 compilation, I put in the project file:

QMAKE_CXXFLAGS += -std=c++14

However, when building project, the IDE generates the following command:

g++ -c -pipe -std=c++14 -g -O0 -g -std=gnu++11 -Wall -W -D_REENTRANT ...

As seen, the generated makefile puts the flag -std=gnu++11 which overrides the flag for C++14 . This did not happen with my previous distro (LTS 12.04, same qt creator version).

I tried with

CONFIG += -std=c++14

But the behavior is the same.

Could someone give any clue?

Instead of:

CONFIG += -std=c++14

Use:

CONFIG += c++14

You can fix it radically. By changing config files.

First of all you need the library path, used in your project. The path you can determine looking at Projects panel ( Ctrl + 5 ) and remembering the name of a "Kit" over the (Build|Run) buttons, then follow the Tools -> Options -> Build & Run -> Kits , select the "Kit" you remember previously, then you can see Qt version: line contents, after that on Qt versions tab you can see the corresponding full library path you need. In my case I see /usr/local/Qt-5.4.1/ .

In /usr/local/Qt-5.4.1/mkspecs/common/g++-base.conf file (you may have another path for Qt library installed), you can change QMAKE_CXXFLAGS_CXX11 or QMAKE_CXXFLAGS_CXX14 (if any) variable to whatever you want (say, to -std=gnu++1z ).

For clang the path became /usr/local/Qt-5.4.1/mkspecs/common/clang.conf in my case.

For some other targets/compilers you may should to follow Tools -> Options -> Build & Run -> Kits -> (select Kit you use) -> (look at 'Qt mkspec:' line at bottom) then find in /usr/local/Qt-5.4.1/mkspecs/*/qmake.conf (where * is Qt mkspec: line contents) and in all included *.conf files a string QMAKE_CXXFLAGS_CXX11 or QMAKE_CXXFLAGS_CXX14 , that you need. Then change its value appropriately.

Then of course you need to use CONFIG += c++11 or CONFIG += c++14 , as Jon Harper mentioned in his answer .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM