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

标签 c++ eclipse c++11 eclipse-cdt devtoolset

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

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

[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++ 构建 >> 设置 >> 方言 >> “其他方言标志”下设置方言,值为“-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"

我试过将“语言标准”选项与“-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 和您正在寻找的功能的新编译器版本。

关于c++ - Eclipse/g++ 无法识别 "-std=c++11"标志,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30604028/

相关文章:

c++ - 浮点运算

c++ - 在 `[likely]]` 语句中正确使用 C++20/`[[unlikely]]` `switch`

c - 与 2 个具有不同 spi 模式的设备的 Spi 连接

c++ - 命令提示符 "runas user:<admin-user> <command>"未正确执行

java - GAE 开发 - 开发环境设置(HotSwap)

eclipse - 在 Eclipse 中调试 Hive?

c++ - 模板类中模板类的结构体

c++ - 如何使继承的虚函数不可用?

c++ - 转发引用始终被视为右值引用

c++ - AWS : cannot execute binary file