Iro*_*ney 5 c++ clang variant qt-creator c++17
不久前我遇到了问题,让 std::variant 在 QtCreator 项目中工作,在这里面临类似的抱怨:
无法在 QtCreator 中使用 g++ 7.2 使用 c++17 功能
我解决了这个问题,并且已经愉快地在这个项目上工作了一段时间,没有出现进一步的问题。它在 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
Run Code Online (Sandbox Code Playgroud)
我可以在编译器输出中的短语“-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 \
^
Run Code Online (Sandbox Code Playgroud)
因此,如您所见,设置了 -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
Run Code Online (Sandbox Code Playgroud)
并且在该行末尾附近再次提到了带有包含标志的 clang:
-I../../../../Programming/Qt/5.10.0/gcc_64/mkspecs/linux-clang
Run Code Online (Sandbox Code Playgroud)
我有四重检查套件,其中 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,所以无论如何这不应该是我问题的原因吗?
正如 Galik 上面指出的,编译器标志“-std=gnu++11”位于标志“-std=c++17”之后,因此会覆盖它,这就是导致此错误的原因。
然而,这个额外标志在我的编译器输出中的出现目前还是一个谜。它仅在使用 Clang 构建时出现,而不是使用 GCC 构建,并且出于某种原因,当选择以下任何套件时,QtCreator 会使用 Clang 构建:
Clang 发布、Clang 调试、GCC 调试。
但使用此套件时则不然:
海湾合作委员会发布。
我已经彻底检查了选项和工具包设置,并且看不到任何错误,因此我将为这些问题打开一个更合适的新问题,并且在回答后我将在原始问题中发布链接,以防其他人阅读我的问题也有这些问题。
| 归档时间: |
|
| 查看次数: |
4650 次 |
| 最近记录: |