如何在 Eclipse Juno/Kepler/Luna CDT 中启用 C++11? [英] How to enable C++11 in Eclipse Juno/Kepler/Luna CDT?

查看:50
本文介绍了如何在 Eclipse Juno/Kepler/Luna CDT 中启用 C++11?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

事实证明这真的不是 Eclipse Kepler 特有的.我必须对 Eclipse Juno 使用相同的过程.问题是在回答同一问题的其他帖子中似乎缺少步骤.

It turns out this really isn't specific to Eclipse Kepler. I had to use the same process for Eclipse Juno. The problem was that there seem to be missing steps in other posts answering this same question.

我正在将 Eclipse Kepler 用于 C++,而我正在尝试使用 C++11 并出现错误.当我编译时出现错误

I'm using Eclipse Kepler for C++ and I'm trying to use C++11 and getting errors. When I compile I get the error

错误:C++98 模式下不允许基于范围的 for 循环

error: range-based-for loops are not allowed in C++98 mode

我已按照帖子中的说明进行操作

I've followed the instructions from the post

Eclipse CDT C++11/C++0x 支持

并且为 Eclipse Juno 提供的解决方案不起作用.

and the solution given for Eclipse Juno isn't working.

不同的评论建议重新启动eclipse并清理和重建.这并没有什么不同.

Different comments have suggested restarting eclipse and cleaning and rebuilding. That hasn't made a difference.

推荐答案

你需要做两件事,首先你需要设置你的编译器,然后你需要设置 CDT 的语言处理器.由于您没有提到您使用的是哪个编译器,我假设它是 GCC,但其他编译器的步骤类似.(请注意,当然,您需要一个支持 C++11 的编译器.)

There's two things you have to do, first you need to setup your compiler, then you need to setup CDT's language processor. Since you didn't mention which compiler you're using, I'll assume it's GCC but the steps will be similar for other compilers. (Note that you need a compiler that supports C++11, of course.)

设置编译器相当简单:

  1. 右键单击您的项目,然后单击属性"
  2. 在 C/C++ Build 下点击设置
  3. 在 GCC C++ Compiler 下,单击 Miscellaneous
  4. 在其他标志"框中,将-std=c++11"附加到标记列表中.
  5. 点击应用和确定

此时您应该能够重建您的项目并使其运行.但是 CDT 仍然可能会显示 C++11 包含的错误.解决方法如下:

At this point you should be able to rebuild your project and get it to run. But CDT still may show errors for C++11 includes. Here's how you can resolve that:

  1. 右键单击您的项目,然后单击属性"
  2. 在 C/C++ 常规下,单击预处理器包含路径、宏"
  3. 选择提供商标签
  4. 列表中应该有一项内容类似于GCC 内置编译器设置".选择此条目.
  5. 取消选中使用全局提供程序..."选项
  6. 在列表下方有一个框,上面写着获取编译器规范的命令".将-std=c++0x"附加到此.
  7. 使用右侧的向上移动"按钮移动列表顶部的GCC 内置编译器设置"提供程序.
  8. 点击应用,然后点击确定.
  9. 返回 Eclipse 工作区,选择项目菜单、C/C++ 索引,然后单击重新解析未解析的包含".

这篇关于如何在 Eclipse Juno/Kepler/Luna CDT 中启用 C++11?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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