2017-05-27 55 views
0

我想介紹使用CMake來構建我的C++項目。當我運行使我得到一個錯誤:CMake target_compile_features unordered_map

[ 11%] Building CXX object CMakeFiles/game.dir/InputHandler.cpp.o 
In file included from /usr/include/c++/5/unordered_map:35:0, 
... 
/usr/include/c++/5/bits/c++0x_warning.h:32:2: error: #error This file requires compiler and library support for the ISO C++ 2011 standard. This support must be enabled with the -std=c++11 or -std=gnu++11 compiler options. 
#error This file requires compiler and library support... 

我意識到這是因爲CMake的不調用C++ 11時,它需要以使使用unordered_map的。谷歌搜索後,我知道我需要在我的CMakeLists.txt中使用target_compile_features()。但是我找不到任何給我提供我需要使用的語法/參數的地方,這裏只是一些例子。 CMake的頁面上它給:

add_library(mylib requires_constexpr.cpp) 
target_compile_features(mylib PRIVATE cxx_constexpr) 

但我不需要cxx_constexpr,我甚至不知道那是什麼。我需要unordered_map。

任何人都可以告訴我我需要使用的語法,最好給我一些參考有效值傳遞到該函數。

回答

0

std::unordered_map是STL的一部分,它不是一種語言關鍵字像constexproverride等CMake的不提供編譯STL的功能特性(這將是落實一項艱鉅的任務!)。就你而言,你真的只是想告訴CMake你需要C++ 11。 This article提供了所有的細節,你應該需要對這個話題,但總結它這個特殊的問題,將靠近你CMakeLists.txt文件的頂部以下應該給你你需要的東西:

set(CMAKE_CXX_STANDARD 11) 
set(CMAKE_CXX_STANDARD_REQUIRED ON) 
set(CMAKE_CXX_EXTENSIONS OFF)