C++ Can';t使用c++;使用g+的17个功能+;7.2在QtCreator中
我最近将gcc和g++更新为7.2版。我想特别试用C++ Can';t使用c++;使用g+的17个功能+;7.2在QtCreator中,c++,qt-creator,c++17,variant,C++,Qt Creator,C++17,Variant,我最近将gcc和g++更新为7.2版。我想特别试用std::experimental::any和std::variant,我正在QtCreator中使用qt5.9.1 到目前为止,我已经在项目文件中写了以下内容: CONFIG += c++17 我在正确的位置添加了正确的标题: #include <variant> #include <experimental/any> #错误此文件需要编译器和库支持\ ^~~~~ 我在项目文件中尝试了多种方法,以下是完整列表: CO
std::experimental::any
和std::variant
,我正在QtCreator中使用qt5.9.1
到目前为止,我已经在项目文件中写了以下内容:
CONFIG += c++17
我在正确的位置添加了正确的标题:
#include <variant>
#include <experimental/any>
#错误此文件需要编译器和库支持\
^~~~~
我在项目文件中尝试了多种方法,以下是完整列表:
CONFIG += c++17
&
&
&
&
&
&
这是我能想到的每一次暗中刺杀。我错过了什么?为什么experimental::any
在variant不编译时编译
我知道我不应该以这种方式同时使用CONFIG+=c++xx
和QMAKE_cxflags
,但我想我会试试看,因为其他方法都不管用。对于加分,我还想知道,当我已经为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\u cxflags+=-std=c++17
。但是他很快删除了他的评论,因此我无法亲自感谢他为我检查文档所做的努力。CONFIG+=c++17
可用于Qt 5.12及更高版本
对于Qt5.11和更早的版本,您的手必须弄脏一点
添加QMAKE\u cxflags+=-std=c++17
完成了GCC&Clang的工作;对于MSVC,您将/std:c++17
或/std:c++最新版本
用于Windows:
我正在下载qt-opensource-windows-x86-5.11.1,包括MinGW32。
对于MinGW64,我下载qt-5.5.0-x64-mingw510r0-seh-rev0,只安装编译器。
配置QtCreator,如所示。
创建新项目并将QMAKE_cxflags+=-std=gnu++1z添加到.pro文件()。
对于测试,请尝试编译以下简单代码:
#include <optional>
std::optional<int> foo()
{
return std::nullopt;
}
int main(int argc, char *argv[])
{
foo();
}
#包括
std::可选的foo()
{
返回std::nullopt;
}
int main(int argc,char*argv[])
{
foo();
}
编辑2019年3月:从Qt5.12开始,您可以使用CONFIG+=c++17
实际标志是
c++1z
,而不是c++17
。简而言之,要获得C++17支持,您不需要修改QMAKE_cxflags
,只需使用CONFIG+=C++1z
关于为什么可以的讨论,但它相当于“在c++17标准化之前,我们将其实现为c++1z
,现在我们不必麻烦给它加别名了。”
注意:我意识到你只是需要一次清洁和重建。我正在回答一个基本问题“启用C++17支持需要使用哪些标志?”通过示例C++17 C++20在Linux(或Windows上的类似版本)上使用Qt5版本5.15.3(及以上)构建
摘要:
在CMakeLists.txt文件中,用于用C++17编写并使用Qt的应用程序
cmake_minimum_required(VERSION 3.16.0)
project(helloworld VERSION 1.0.0 LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
对于c++17,qt项目配置如mygame.pro可能具有c++1z,对于c++20,可能具有c++2a,对于较旧的项目,可能具有c++11:
CONFIG += c++1z
在configure(例如C++20项目配置)的命令行上,始终使用卷影生成:
../configure -c++std c++2a
cmake --build .. --parallel
Windows或Linux编译器命令参数示例(带或不带qt);在编写时,C++20是C++2a,C++17是C++1z,其他人也跟着写
$ g++ -std=c++2a hello_linux_is_the_worlds_device_future.cpp
c:\hello> cl /std=c++1z /EHsc hello_windows_is_in_decline.cpp
在windows上,请注意正/斜杠
更多详细信息:
我发现建立一个新的C++项目,甚至建立QT5开源的“强>所有< /强>,从而创建自己的QT版本(这是很困难的)是可能的,由C++ 17或C++ 20(QT6至少需要C++ 17)。我克隆并签出了qt5 5.15版本,即所有的qt5开源版本,并使用C++20构建它-构建需要23GB你不需要做所有这些。
注意下面的配置示例,。。。在一台快速的PC上运行4个小时是非常麻烦的,我最终成功了。无论如何,问题是Qt5.15很乐意使用C++17或C++20设置(在我的例子中使用gcc g++-8或g++-9)构建自己,例如:
-跳过qtdocgallery-c++std c++2a-确认许可证-opengl桌面
-平台linux-g++-64#请把这些都放在一行上 cmake--构建--平行的
我非常小心地写下这篇文章作为我自己的笔记,并与大家分享,我很高兴自己进行更正,欢迎大家提出建议;永远不要侵入作者的作品并改变它!正如我不会去公共图书馆从书中删除页面一样。示例比非解决方案更重要,但示例的老化速度更快 在底部应该有一个选项卡“编译输出”。有哪些以“-std=”开头的标志?请注意,它们可能有多个,只有最后一个才算。这是一个很好的观点,我不想检查。它提到no-std=flags。是否需要在特定位置添加配置行?编译器输出被添加到问题…右键单击您的项目,选择“清理”,然后选择“运行qmake”。由于某些原因,我永远无法理解更改.pro文件并不总是正确更新makefile。该死的!只要我使用的是QMAKE_cxflags+=-std=c++17,而不是配置等价物,它在我清理和重建之后就可以工作。谢谢你,伙计!有人确实简短地写了一篇评论,说这些文档没有显示对CONFIG+=c++17的支持。他删除了他的评论,但如果他正在读这篇文章,
CONFIG += c++11
CONFIG += c++14
CONFIG += c++17
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.
#include <optional>
std::optional<int> foo()
{
return std::nullopt;
}
int main(int argc, char *argv[])
{
foo();
}
cmake_minimum_required(VERSION 3.16.0)
project(helloworld VERSION 1.0.0 LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
CONFIG += c++1z
../configure -c++std c++2a
cmake --build .. --parallel
$ g++ -std=c++2a hello_linux_is_the_worlds_device_future.cpp
c:\hello> cl /std=c++1z /EHsc hello_windows_is_in_decline.cpp