如何激活C ++ 11在CMake? [英] How to activate C++ 11 in CMake?

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

问题描述

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

When I try to run CMake generated makefile to compile my program, I get the error that


在C ++ 98模式。

range based for loops are not supported in C++ 98 mode.

我尝试添加 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 ,我获得:


g ++(Ubuntu / Linaro 4.6.1-9ubuntu3)4.6.1

g++ (Ubuntu/Linaro 4.6.1-9ubuntu3) 4.6.1

我也试过了 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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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