当-std = c ++ 17在编译器输出中时,使用-std ++ 17标志请求为std :: variant启用c ++ 17支持的编译器

问题描述 投票:4回答:1

我有一段时间没有让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,所以这不应该成为我的问题的原因吗?

c++ clang qt-creator c++17 variant
1个回答
4
投票

正如Galik在上面指出的那样,编译器标志“-std = gnu ++ 11”位于标志“-std = c ++ 17”之后,因此会覆盖它,这是导致此错误的原因。

然而,在我的编译器输出中出现这个额外标志是一个谜。它只在与Clang一起构建时出现,而不是与GCC一起构建,并且出于某种原因,QtCreator在选择以下任何一个套件时与Clang一起构建:

Clang Release,Clang Debug,GCC Debug。

但不是在使用此套件时:

GCC发布。

我已经彻底检查了选项和工具包设置,我看不出任何错误,所以我会针对这些问题打开一个新的更合适的问题,我会在回答原始问题时发布链接以防其他人阅读我的问题问题也有这些问题。

© www.soinside.com 2019 - 2024. All rights reserved.