不能在QtCreator中使用g ++ 7.2使用c ++ 17功能

Iro*_*ney 22 c++ variant qt-creator c++17

我最近将gcc和g ++更新到版本7.2.我想尝试一下std::experimental::any,std::variant特别是,我在QtCreator中使用Qt 5.9.1.

到目前为止,我已经在项目文件中写了这个:

CONFIG += c++17
Run Code Online (Sandbox Code Playgroud)

我在正确的位置添加了正确的标题:

#include <variant>
#include <experimental/any>
Run Code Online (Sandbox Code Playgroud)

任何工作都很好,没有问题.但是,当我包含变体头文件时,我收到此错误:

/usr/include/c++/7/bits/c++17_warning.h:32: error: #error This file requires compiler and library support for the ISO C++ 2017 standard. This support must be enabled with the -std=c++17 or -std=gnu++17 compiler options.
Run Code Online (Sandbox Code Playgroud)

#error此文件需要编译器和库支持\ ^ ~~~~

我在项目文件中尝试过各种各样的东西,这里是完整列表:

CONFIG += c++17
Run Code Online (Sandbox Code Playgroud)

&

CONFIG += c++1z
Run Code Online (Sandbox Code Playgroud)

&

QMAKE_CXXFLAGS += -std=c++17
Run Code Online (Sandbox Code Playgroud)

&

QMAKE_CXXFLAGS += -std=c++1z
Run Code Online (Sandbox Code Playgroud)

&

CONFIG += c++17
QMAKE_CXXFLAGS += -std=c++17
Run Code Online (Sandbox Code Playgroud)

&

CONFIG += c++1z
QMAKE_CXXFLAGS += -std=c++1z
Run Code Online (Sandbox Code Playgroud)

&

CONFIG += c++11
CONFIG += c++14
CONFIG += c++17
Run Code Online (Sandbox Code Playgroud)

这是我能想到的黑暗中的每一次刺痛.我错过了什么?为什么experimental::any编译时变种不?

我知道我不应该使用CONFIG += c++xx,并QMAKE_CXXFLAGS以这种方式在一起,但我想我给它一个去为没有其他作品.对于奖励积分,我也想知道,当我已经配置为17时,我应该添加14和11的CONFIG调用吗?

编辑:

这是编译器输出,我的大多数文件名被清除:

18:04:10: Running steps for project AIQt...
18:04:10: Configuration unchanged, skipping qmake step.
18:04:10: Starting: "/usr/bin/make" 
/home/pete/Qt/5.9.1/gcc_64/bin/qmake -o Makefile ../AIQt/AIQt.pro -spec linux-g++ CONFIG+=debug CONFIG+=qml_debug
WARNING: Failure to find: ../src/stdafx.h
WARNING: Failure to find: ../src/Csound/csd.h
g++ -c -pipe -g -Wall -W -D_REENTRANT -fPIC -DQT_DEPRECATED_WARNINGS -DQT_QML_DEBUG -DQT_DATAVISUALIZATION_LIB -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -I../AIQt -I. -I../src -I../src/AIBase -I../src/Maths -I../src/Random -isystem /usr/local/include/csound -I../../../../Qt/5.9.1/gcc_64/include -I../../../../Qt/5.9.1/gcc_64/include/QtDataVisualization -I../../../../Qt/5.9.1/gcc_64/include/QtWidgets -I../../../../Qt/5.9.1/gcc_64/include/QtGui -I../../../../Qt/5.9.1/gcc_64/include/QtCore -I. -isystem /usr/include/libdrm -I. -I../../../../Qt/5.9.1/gcc_64/mkspecs/linux-g++ -o main.o ../AIQt/main.cpp
In file included from /usr/include/c++/7/variant:35:0,
                 from ..###,
                 from ..###,
                 from ..###,
                 from ..###,
                 from ..###,
                 from ..###,
                 from ..###,
                 from ..###:
/usr/include/c++/7/bits/c++17_warning.h:32:2: error: #error This file requires compiler and library support for the ISO C++ 2017 standard. This support must be enabled with the -std=c++17 or -std=gnu++17 compiler options.
 #error This file requires compiler and library support \
  ^~~~~
In file included from ..###,
                 from ..###
                 from ..###,
                 from ..###,
                 from ..###,
                 from ..###,
                 from ..###:
../src/AIBase/Geno.h:70:18: error: ‘variant’ in namespace ‘std’ does not name a type
             std::variant m_valueVariant;
                  ^~~~~~~
In file included from ..###,
                 from ..###,
                 from ..###,
                 from ..###,
                 from ..###,
                 from ..###:
../src/AIBase/Pheno.h:22:13: warning: type qualifiers ignored on function return type [-Wignored-qualifiers]
             const double getGenoValue(size_t genoIndex) const;
             ^~~~~
../src/AIBase/Pheno.h:24:13: warning: type qualifiers ignored on function return type [-Wignored-qualifiers]
             const UserRating getRating() const;
             ^~~~~
In file included from ..###,
                 from ..###:
../AIRadioQt/GraphDialog.h:16:15: warning: declaration ‘struct ar::ai::ClusterList’ does not declare anything
 class ar::ai::ClusterList;
               ^~~~~~~~~~~
make: *** [main.o] Error 1
18:04:13: The process "/usr/bin/make" exited with code 2.
Error while building/deploying project AIQt (kit: Qt 5.9.1 GCC 64bit)
The kit Qt 5.9.1 GCC 64bit has configuration issues which might be the root cause for this problem.
When executing step "Make"
18:04:13: Elapsed time: 00:03.
Run Code Online (Sandbox Code Playgroud)

回答:

正如nwp所提到的,我只需要清理它并重建.

另一张海报也评论说CONFIG += c++17似乎还没有支持,所以有必要使用QMAKE_CXXFLAGS += -std=c++17.他很快删除了他的评论,所以我无法亲自感谢他为我检查文档的努力.

min*_*xew 29

由于Qt的5.11,CONFIG += c++17还没有一个公认的QMAKE标志.(更新:从Qt 5.12开始,它是公认的)

添加QMAKE_CXXFLAGS += -std=c++17GCC&Clang的工作; 对于MSVC,您可能需要指定 /std:c++17/std:c++latest.

  • `CONFIG += c++17` 无法在 Windows 10 上使用 MinGW 7.3.0 64 位的 Qt 5.12.1 完成工作。然而,“QMAKE_CXXFLAGS += -std=c++17”仍然可以完成工作。 (3认同)
  • 带有CONFIG + = c ++ 17和QMAKE_CXXFLAGS + = -std = c ++ 17的QtCreator 4.6和Qt 5.10在这里工作。 (2认同)
  • @Alexander也许是特定于构建工具的。对于MSVC,我必须将第二个更改为`QMAKE_CXXFLAGS + = / std:c ++ 17`-通过检查显式设置的VS2017 C ++项目的生成输出,我获得了格式正确的MSVC C ++ 17标志。到c ++ 17。 (2认同)

Jon*_*per 9

实际的标志是CONFIG += c++17,而不是c++1z.简而言之,要获得C++ 17支持,您不需要修改c++17,而只需使用即可QMAKE_CXXFLAGS.

讨论原因可以在这个错误报告中找到,但它几乎相当于"我们CONFIG += c++1z在C++ 17标准化之前实现了它,现在我们不会打扰别名".

注意:我意识到你只需要一个干净的重建.我正在回答"我需要使用哪些标志来启用C++ 17支持?"的基本问题.