问题描述
当我尝试运行CMake生成的makefile来编译程序时,出现以下错误
When I try to run a CMake generated makefile to compile my program, I get the error that
我尝试添加 add_definitions(-std = c ++ 0x)
到我的 CMakeLists.txt
,但这没有帮助。
I tried adding add_definitions(-std=c++0x)
to my CMakeLists.txt
, but it did not help.
我也尝试过:
if(CMAKE_COMPILER_IS_GNUCXX)
add_definitions(-std=gnu++0x)
endif()
我做 g ++ --version
时,我得到:
我也尝试过 SET(CMAKE_CXX_FLAGS -std = c ++ 0x)
,这也行不通。
I have also tried SET(CMAKE_CXX_FLAGS "-std=c++0x")
, which also does not work.
我不明白如何使用CMake激活C ++ 11功能。
I do not understand how I can activate C++ 11 features using CMake.
推荐答案
事实证明, SET(CMAKE_CXX_FLAGS -std = c ++ 0x)
确实激活了许多C ++ 11功能。它不起作用的原因是该语句看起来像这样:
As it turns out, SET(CMAKE_CXX_FLAGS "-std=c++0x")
does activate many C++11 features. The reason it did not work was that the statement looked like this:
set(CMAKE_CXX_FLAGS "-std=c++0x ${CMAKE_CXX_FLAGS} -g -ftest-coverage -fprofile-arcs")
按照这种方法, -std = c ++ 0x
标志被覆盖,因此无法正常工作。
Following this approach, somehow the -std=c++0x
flag was overwritten and it did not work. Setting the flags one by one or using a list method is working.
list( APPEND CMAKE_CXX_FLAGS "-std=c++0x ${CMAKE_CXX_FLAGS} -g -ftest-coverage -fprofile-arcs")
这篇关于如何在CMake中激活C ++ 11?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!