【发布时间】:2017-12-21 15:41:48
【问题描述】:
前段时间我在让 std::variant 在 QtCreator 项目中工作时遇到了问题,在这里遇到了类似的投诉:
Can't use c++17 features using g++ 7.2 in QtCreator
我解决了这个问题,并且很高兴地在这个项目上工作了一段时间,没有其他问题。它在 ubuntu 14.04 上运行,使用 GCC 7.2.0 构建,并且也在 clang 5.0 下构建。
两天前,我备份了所有内容,安装了最新的 QtCreator,再次安装了我的所有工具(gcc 7.2.0 和 clang 5.0)检索了我的项目并尝试构建。构建失败,说明:
/usr/include/c++/7.2.0/bits/c++17_warning.h:32:错误:此文件 需要对 ISO C++ 2017 标准的编译器和库支持。 必须使用 -std=c++17 或 -std=gnu++17 启用此支持 编译器选项。
在我的项目文件中,我已经有了这个:
QMAKE_CXXFLAGS += -std=c++17
我可以在编译器输出中的短语“-std=c++17”中看到。这是直到第一个错误之前的完整编译器输出:
15:08:37: Running steps for project AIRadioQt...
15:08:37: Skipping disabled step qmake.
15:08:37: Starting: "/usr/bin/make"
/home/pete/Programming/Qt/5.10.0/gcc_64/bin/qmake -o Makefile ../AIRadioQt/AIRadioQt.pro -spec linux-clang CONFIG+=debug CONFIG+=qml_debug
clang++ -c -pipe -std=c++17 -g -std=gnu++11 -Wall -W -D_REENTRANT -fPIC -DQT_DEPRECATED_WARNINGS -DQT_QML_DEBUG -DQT_DATAVISUALIZATION_LIB -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -I../AIRadioQt -I. -I../src -I../src/AIBase -I../src/Maths -I../src/Random -isystem /usr/local/include/csound -I../../../../Programming/Qt/5.10.0/gcc_64/include -I../../../../Programming/Qt/5.10.0/gcc_64/include/QtDataVisualization -I../../../../Programming/Qt/5.10.0/gcc_64/include/QtWidgets -I../../../../Programming/Qt/5.10.0/gcc_64/include/QtGui -I../../../../Programming/Qt/5.10.0/gcc_64/include/QtCore -I. -isystem /usr/include/libdrm -I. -I../../../../Programming/Qt/5.10.0/gcc_64/mkspecs/linux-clang -o main.o ../AIRadioQt/main.cpp
In file included from ../AIRadioQt/main.cpp:1:
In file included from ../AIRadioQt/stdafx.h:9:
In file included from /usr/bin/../lib/gcc/x86_64-linux-gnu/7.2.0/../../../../include/c++/7.2.0/variant:35:
/usr/bin/../lib/gcc/x86_64-linux-gnu/7.2.0/../../../../include/c++/7.2.0/bits/c++17_warning.h:32:2: 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 \
^
因此,如您所见,设置了 -std=c++17 标志。这里的国旗顺序有问题吗?
下一个奇怪的事情是,无论我在 QtCreator 中使用我的 gcc 套件还是 clang 套件,它似乎总是在编译器输出中调用 clang,如下行所示:
clang++ -c -pipe -std=c++17 -g -std=gnu++11 -Wall -W -D_REENTRANT -fPIC -DQT_DEPRECATED_WARNINGS -DQT_QML_DEBUG -DQT_DATAVISUALIZATION_LIB -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -I../AIRadioQt -I. -I../src -I../src/AIBase -I../src/Maths -I../src/Random -isystem /usr/local/include/csound -I../../../../Programming/Qt/5.10.0/gcc_64/include -I../../../../Programming/Qt/5.10.0/gcc_64/include/QtDataVisualization -I../../../../Programming/Qt/5.10.0/gcc_64/include/QtWidgets -I../../../../Programming/Qt/5.10.0/gcc_64/include/QtGui -I../../../../Programming/Qt/5.10.0/gcc_64/include/QtCore -I. -isystem /usr/include/libdrm -I. -I../../../../Programming/Qt/5.10.0/gcc_64/mkspecs/linux-clang -o main.o ../AIRadioQt/main.cpp
它在该行末尾附近再次提到了clang,并带有这个包含标志:
-I../../../../Programming/Qt/5.10.0/gcc_64/mkspecs/linux-clang
我已经检查了四重套件,GCC 的肯定叫 GCC 和 GCC++,而 Clang 的肯定叫 Clang 和 Clang++。我已经检查了可执行链接并逐步遵循它们的链接路径,/usr/bin/gcc 肯定链接到 /usr/bin/x86_64-linux-gnu-gcc-7 和 /usr/bin/g++ 肯定链接到 /usr /bin/x86_64-linux-gnu-g++-7。所以我很困惑为什么当我选择了 GCC 套件时它坚持调用 Clang 而不是 GCC!无论如何,我的 GCC 和 Clang 版本都支持 c++17,所以这不应该是我的问题的原因吗?
【问题讨论】:
-
-std=gnu++11出现在之后-std=gnu++17在命令行上。也许它会覆盖它? -
好的,不知道你是否拥有它完全就像他们拥有它一样。我将删除我的旗帜。我认为该问题中的一些小问题可能已经解决了。
-
@Galik 也许如果它是
-std=gnu++17它会被修复?我不确定,我通常不使用 QtCreator。 -
@Galik 我想知道类似的东西。这是这样工作的吗?理想情况下是否应该只显示一个标志?我的 QtCreator 项目文件只提到了 c++17 标志,QtCreator 或我的工具包设置中的其他地方是否有可能添加额外标志的选项?
-
我猜最后一个旗子赢了。
标签: c++ clang qt-creator c++17 variant