本文介绍了如何激活C ++ 11在CMake?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试运行CMake生成makefile来编译我的程序时,我得到的错误是

When I try to run 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. I tried this too:

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")

这篇关于如何激活C ++ 11在CMake?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-21 00:58