Eclipse/g++ 无法识别“-std=c++11”标志

Eclipse / g++ not recognizing "-std=c++11" flag

我是 运行 CentOS 6.6 x64,带有 Eclipse Luna 和 g++ 4.7.2(由 devtoolset-2 提供)。我正在使用 Eclipse 的内置自动 Makefile 生成。

我已经使用 scl enable devtoolset-2 启用了 g++ 4.7.2 bash

[me@dev ~]# g++ --version g++ (GCC) 4.7.2 20121015 (Red Hat 4.7.2-5) Copyright (C) 2012 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

不幸的是,在编译时,Eclipse 抛出错误,指出“-std=c++11”不是有效选项。我在项目属性 >> C/C++ 构建 >> 设置 >> 方言 >> "Other dialect flags" 下设置了方言,值为“-std=c++11”。

Invoking: GCC C++ Compiler make: *** Waiting for unfinished jobs.... g++ -std=c++11 .... cc1plus: error: unrecognized command line option "-std=c++11"

我试过将 "Language Standard" 选项与“-std=c++0x”一起使用,但它在编译时抛出错误

map<int, MyObject*> myObjectMap; 
// assume I've added in objects before the loop
for (const auto& kv : myObjectMap) // line 249
{
    // do things
}

249: error: expected initializer before ‘:’ token

如果您希望 Eclipse 与安装的 devtoolset-2 一起工作,您需要从启用 devtoolset 的环境中启动 Eclipse。最明显的是,这可以通过

的终端来完成
scl enable devtoolset-2 eclipse &

说明:devtoolset 作为替代开发环境安装,默认情况下 处于活动状态。只有明确激活后,您才会获得理解 -std=c++11 和您正在寻找的功能的新编译器版本。