无法在 QtCreator 中使用 g 7.2 使用 c 17 功能

新手上路,请多包涵

我最近将 gcc 和 g++ 更新到了 7.2 版。我想特别尝试 std::experimental::anystd::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++xxQMAKE_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 。不过,他很快删除了他的评论,所以我无法亲自感谢他为我检查文档所做的努力。

原文由 Iron Attorney 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 1.1k
1 个回答

CONFIG += c++17 可用于 Qt 5.12 及更高版本。

对于 Qt 5.11 和更早的版本, 它不是一个公认的 QMake 标志,你必须弄脏你的手。

添加 QMAKE_CXXFLAGS += -std=c++17 为 GCC 和 Clang 做这项工作;对于 MSVC,您 可能需要指定 /std:c++17/std:c++latest

原文由 minexew 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题