Qt:CONFIG += C++11,但 -std=c++0x

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19523412/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 22:55:55  来源:igfitidea点击:

Qt: CONFIG += C++11, but -std=c++0x

c++c++11mingwqt-creatorqt5.1

提问by Horst Walter

When I compile a project under Qt Creator 2.8 / Qt5.1with VS 2010 all is fine. If I do the same with MinGW I get the following error.

当我使用 VS 2010在Qt Creator 2.8 / Qt5.1下编译项目时一切正常。如果我对 MinGW 做同样的事情,我会收到以下错误。

 error: #error This file requires compiler and library support for the ISO C++ 2011 standard. This support is currently experimental, and must be enabled with the -std=c++11 or -std=gnu++11 compiler options.

I understand I need to enable C+11, but I have CONFIG += console c++11in my .pro file. Is this not what is needed? What am I doing wrong?

我知道我需要启用 C+11,但CONFIG += console c++11我的 .pro 文件中有。这不是需要的吗?我究竟做错了什么?

When I look at the make I see:

当我查看品牌时,我看到:

CXXFLAGS      = -pipe -fno-keep-inline-dllexport -g -std=c++0x

Confusing, as I say c++11 in the pro file.

令人困惑,正如我在 pro 文件中所说的 c++11。

  1. Have deleted everything, run qmakeetc, from the scratch, no result
  2. As said, with VS2010 it works
  3. Using the MinGW with gcc 4.8.0 from here. http://qt-project.org/downloads
  4. If this matters, Win7 32
  1. qmake从头开始删除所有内容,运行等,没有结果
  2. 如上所述,使用 VS2010 它可以工作
  3. 从这里使用带有 gcc 4.8.0 的 MinGW。http://qt-project.org/downloads
  4. 如果这很重要,Win7 32

Checked:

检查:

Found solution, but can only accept it in some time: https://stackoverflow.com/a/19530028/356726

找到解决方案,但只能在一段时间内接受:https: //stackoverflow.com/a/19530028/356726

采纳答案by Horst Walter

Ok, thanks to your hints I have figured it out.

好的,多亏了你的提示,我已经弄清楚了。

After I have tried any possible advice from above, with still no success, I have excluded any subproject I could think of in my project. Eventually I have found a QML sample .pro which did not have CONFIG += c++11defined.

在我尝试了上面的任何可能的建议后,仍然没有成功,我已经排除了我可以在我的项目中想到的任何子项目。最终我找到了一个没有CONFIG += c++11定义的 QML 示例 .pro 。

That was causing the error. So the root cause was not the project I was working on, but a subproject which however got compiled in the same step.

那是导致错误的原因。所以根本原因不是我正在处理的项目,而是一个在同一步骤中编译的子项目。

回答by Michael Burr

Try changing the mkspecs/win32-g++/qmake.confline that says:

尝试更改以下mkspecs/win32-g++/qmake.conf行:

QMAKE_CXXFLAGS_CXX11    = -std=c++0x

to:

到:

QMAKE_CXXFLAGS_CXX11    = -std=c++11

and re-run qmake.

并重新运行qmake。



Some additional details:

一些额外的细节:

Adding the "c++11" feature to the CONFIGqmake variable causes the mkspecs/features/c++11.prffile to be pulled in (see the "Adding New Configuration Features" section of the qmake Advanced Usagedocument for details).

将“c++11”功能添加到CONFIGqmake 变量会导致mkspecs/features/c++11.prf文件被拉入(有关详细信息,请参阅qmake 高级用法文档的“添加新配置功能”部分)。

That qmake profile has a QMAKE_CXXFLAGS += $$QMAKE_CXXFLAGS_CXX11line among other things which configure C++11 support. So adding "c++11" to the CONFIG variable is the proper way to indicate that you want c++11 support to qmake, as you mentioned in a comment.

该 qmake 配置文件有QMAKE_CXXFLAGS += $$QMAKE_CXXFLAGS_CXX11一行配置 C++11 支持。因此,正如您在评论中提到的那样,将“c++11”添加到 CONFIG 变量是表明您希望 c++11 支持 qmake 的正确方法。

回答by TonyK

I am using Qt Creator 2.7.2, and I have this line in my .pro file:

我正在使用 Qt Creator 2.7.2,并且我的 .pro 文件中有这一行:

QMAKE_CXXFLAGS += -std=c++11

Does this work for you?

这对你有用吗?

回答by edwinc

qmake will use whatever flags one has for c++11. So you can overwrite them like:

qmake 将使用 c++11 的任何标志。所以你可以像这样覆盖它们:

unix:QMAKE_CXXFLAGS_CXX11 = -std=c++11

unix:QMAKE_CXXFLAGS_CXX11 = -std=c++11

CONFIG *= c++11

配置 *= c++11

You can even tell it to use -std=c++14 or -std=c++17 instead when c++11 is added to the config as older qmake's might not be aware of them.

您甚至可以告诉它在将 c++11 添加到配置时使用 -std=c++14 或 -std=c++17 代替,因为较旧的 qmake 可能不知道它们。