2017-10-06 93 views
2

我最近更新了gcc和g ++到版本7.2。我想特別嘗試std::experimental::anystd::variant,我在QtCreator中使用Qt 5.9.1。有不能在QtCreator中使用g ++ 7.2使用C++ 17功能

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

任何工作正常,沒有任何問題:

到目前爲止,我已經在項目文件中這樣寫:

CONFIG += c++17 

而且我已經在正確的位置添加正確的標題。然而,當我包括變種的頭文件,我得到這個錯誤:

/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此文件需要編譯器和庫支持\ ^ ~~~~

我曾嘗試在各種各樣的東西項目文件,這裏是完整的列表:

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編譯變體時不?

我知道我不應該使用CONFIG += c++xxQMAKE_CXXFLAGS這種方式,但我想我會放棄它,因爲沒有別的工作。對於獎勵積分,我也想知道,我是否應該在CONFIG爲17時添加14和11的CONFIG呼叫?

編輯:

這裏是我的大多數文件名的編譯器輸出洗出:

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_CXXFLAGS += -std=c++17。雖然他很快刪除了他的評論,但我無法親自感謝他爲我檢查文檔的努力。

+1

在底部應該有一個標籤「編譯輸出」。什麼標誌以「-std =」開頭?請注意,它們可能有多個,只有最後一個數字。 – nwp

+0

這是一個很好的觀點,我沒有想過要檢查。它提到沒有-std =標誌。我是否需要在特定位置添加CONFIG行?編譯器輸出添加到問題... –

+1

右鍵單擊您的項目,然後選擇「清理」,然後選擇「運行qmake」。由於原因,我永遠不會理解改變.pro文件並不總是正確地更新makefile。 – nwp

回答