Compilation of C++14 in qtcreator

我怕爱的太早我们不能终老 提交于 2019-12-07 01:02:51

问题


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?


回答1:


Instead of:

CONFIG += -std=c++14

Use:

CONFIG += c++14



回答2:


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.



来源:https://stackoverflow.com/questions/38293708/compilation-of-c14-in-qtcreator

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!