【发布时间】:2018-03-18 13:41:27
【问题描述】:
我最近将 gcc 和 g++ 更新到了 7.2 版。我特别想尝试std::experimental::any 和std::variant,我在QtCreator 中使用Qt 5.9.1。
到目前为止,我已经在项目文件中写了这个:
CONFIG += c++17
我已经在正确的地方添加了正确的标题:
#include <variant>
#include <experimental/any>
任何工作都很好,没有问题。但是,当我包含变体头文件时,我收到此错误:
/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.
#error 此文件需要编译器和库支持 \ ^~~~~
我在项目文件中尝试了很多东西,这里是完整列表:
CONFIG += c++17
&
CONFIG += c++1z
&
QMAKE_CXXFLAGS += -std=c++17
&
QMAKE_CXXFLAGS += -std=c++1z
&
CONFIG += c++17
QMAKE_CXXFLAGS += -std=c++17
&
CONFIG += c++1z
QMAKE_CXXFLAGS += -std=c++1z
&
CONFIG += c++11
CONFIG += c++14
CONFIG += c++17
这是我能想到的所有黑暗中的刺伤。我错过了什么?为什么experimental::any 编译时变体不编译?
我知道我不应该以这种方式同时使用 CONFIG += c++xx 和 QMAKE_CXXFLAGS,但我想我会试一试,因为没有其他方法。对于奖励积分,我还想知道,当我已经为 17 配置时,是否应该添加 14 和 11 的配置调用?
编辑:
这是我的大部分文件名被清除的编译器输出:
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.
回答:
正如 nwp 所说,我只需要清理并重建它。
另一位发帖人也评论说CONFIG += c++17似乎还不支持,所以有必要使用QMAKE_CXXFLAGS += -std=c++17。不过他很快删除了他的评论,所以我无法亲自感谢他为我检查文档的努力。
【问题讨论】:
-
在底部应该有一个选项卡“编译输出”。有哪些以“-std=”开头的标志?请注意,它们可能有多个,并且只计算最后一个。
-
这是一个好点,我没想过要检查。它没有提到 -std= 标志。我需要在特定位置添加 CONFIG 行吗?编译器输出添加到问题...
-
右键单击您的项目并选择“clean”,然后选择“Run qmake”。由于某些原因,我永远无法理解更改 .pro 文件并不总是能正确更新 makefile。
-
该死的!只要我使用的是 QMAKE_CXXFLAGS += -std=c++17,而不是 CONFIG 等价物,它在我清理和重建后就可以工作。谢啦!有人确实简短地写了一条评论,说明文档没有显示对 CONFIG += c++17 的支持。他删除了他的评论,但如果他正在阅读这篇文章,那是一件很有帮助的事情。随时再次写该评论,我会支持它,哈哈。但是,是的,重建就是答案,非常感谢 nwp。
-
不要在问题中包含答案。相反,发布一个答案并接受它。
标签: c++ qt-creator c++17 variant