简体   繁体   English

在qtcreator中编译C ++ 14

[英]Compilation of C++14 in qtcreator

I have a qt project containing parts in C++14 . 我有一个包含C++14部分的qt项目。

Recently, I changed my ubuntu distro. 最近,我改变了我的ubuntu发行版。 Now I have 16.04 LTS and I installed Qt creator 4.02 (built on jun 13). 现在我有16.04 LTS,我安装了Qt creator 4.02(建于Jun 13)。

In order to enable C++14 compilation, I put in the project file: 为了启用C++14编译,我输入了项目文件:

QMAKE_CXXFLAGS += -std=c++14

However, when building project, the IDE generates the following command: 但是,在构建项目时,IDE会生成以下命令:

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 . 如图所示,生成的makefile放置标志-std=gnu++11 ,它覆盖了C++14的标志。 This did not happen with my previous distro (LTS 12.04, same qt creator version). 我之前的发行版(LTS 12.04,同样的qt创建者版本)没有发生这种情况。

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. 您可以通过(Build|Run)按钮确定查看“ 项目”面板( Ctrl + 5 )并记住“工具包”名称的路径,然后按照Tools -> Options -> Build & Run -> Kits ,选择你记得以前的“Kit”,那么你可以看到Qt version:行内容,在Qt versions选项卡上,你可以看到你需要的相应的完整库路径。 In my case I see /usr/local/Qt-5.4.1/ . 在我的情况下,我看到/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 ). /usr/local/Qt-5.4.1/mkspecs/common/g++-base.conf文件中(您可能有另一个安装Qt库的路径),您可以将QMAKE_CXXFLAGS_CXX11QMAKE_CXXFLAGS_CXX14 (如果有)变量更改为您想要的任何内容(比如说, -std=gnu++1z )。

For clang the path became /usr/local/Qt-5.4.1/mkspecs/common/clang.conf in my case. 对于clang ,在我的情况下,路径变为/usr/local/Qt-5.4.1/mkspecs/common/clang.conf

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. 对于其他一些目标/编译器,您可以按照Tools -> Options -> Build & Run -> Kits -> (select Kit you use) -> (look at 'Qt mkspec:' line at bottom)然后在/usr/local/Qt-5.4.1/mkspecs/*/qmake.conf找到/usr/local/Qt-5.4.1/mkspecs/*/qmake.conf / * /usr/local/Qt-5.4.1/mkspecs/*/qmake.conf (其中*Qt mkspec:行内容),在所有包含的*.conf文件中,您需要一个字符串QMAKE_CXXFLAGS_CXX11QMAKE_CXXFLAGS_CXX14 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 . 然后当然你需要使用CONFIG += c++11CONFIG += c++14 ,就像Jon Harper他的回答中提到的那样。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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