无法在QtCreator中使用g ++ 7.2使用c ++ 17功能 [英] Can't use c++17 features using g++ 7.2 in QtCreator

查看:807
本文介绍了无法在QtCreator中使用g ++ 7.2使用c ++ 17功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近将gcc和g ++更新到了7.2版.我想特别尝试std::experimental::anystd::variant,并且我正在QtCreator中使用Qt 5.9.1.

I have recently updated gcc and g++ to version 7.2. I would like to try out std::experimental::any and std::variant in particular, and I am using Qt 5.9.1 in QtCreator.

到目前为止,我已经将其写在项目文件中:

So far I have written this in the project file:

CONFIG += c++17

我在正确的位置添加了正确的标题:

And I have added the correct headers in the correct places:

#include <variant>
#include <experimental/any>

任何人都可以正常工作,那里没有问题.但是,当我包含变体头文件时,会出现此错误:

Any works fine, no problems there. However, when I include the variant header file, I get this error:

/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此文件需要编译器和库支持\ ^ ~~~~

#error This file requires compiler and library support \ ^~~~~

我已经尝试了项目文件中的各种操作,这是完整列表:

I have tried a variety of things in the project file, here is the full list:

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在变体没有编译时会编译?

That's every stab in the dark I could think of. What am I missing? And why does experimental::any compile when variant doesn't?

我知道我不应该以此方式同时使用CONFIG += c++xxQMAKE_CXXFLAGS,但是我认为我会尝试一下,因为其他方法都无效.为了获得加分,我还想知道,当我已经为17进行配置时,我应该添加针对14和11的CONFIG调用吗?

I know I shouldn't use CONFIG += c++xx and QMAKE_CXXFLAGS together in this way, but I thought I'd give it a go as nothing else works. For bonus points, I'm also wondering, should I add the CONFIG calls for 14 and 11 when I already CONFIG for 17?

这是编译器的输出,其中大部分文件名都被清除了:

Here is the compiler output with most of my filenames scrubbed out:

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所说,我只需要清理并重建.

As mentioned by nwp, I just had to clean it and rebuild.

另一位发帖人也评论说,似乎尚不支持CONFIG += c++17,因此有必要使用QMAKE_CXXFLAGS += -std=c++17.不过,他很快删除了他的评论,所以我个人感谢他为我检查文档的努力.

Another poster also commented that CONFIG += c++17 doesn't appear to be supported yet, so it is necessary to use QMAKE_CXXFLAGS += -std=c++17. He quickly deleted his comment though, so I am unable to thank him personally for going to the effort of checking the docs for me.

推荐答案

CONFIG += c++17可以与Qt 5.12及更高版本一起使用.

CONFIG += c++17 can be used with Qt 5.12 and later.

对于Qt 5.11及更早版本,它不是公认的QMake标记,那么您就必须弄脏手.

For Qt 5.11 and earlier, it is not a recognized QMake flag and you have to get your hands a bit dirty.

添加QMAKE_CXXFLAGS += -std=c++17可以完成GCC和铛;对于MSVC,您可能可能需要指定 /std:c++17/std:c++latest.

Adding QMAKE_CXXFLAGS += -std=c++17 does the job for GCC & Clang; for MSVC you will probably need to specify /std:c++17 or /std:c++latest.

这篇关于无法在QtCreator中使用g ++ 7.2使用c ++ 17功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆