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

查看:277
本文介绍了如何在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 for 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

我遵循了帖子中的说明

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

,并且为Eclipse Juno提供的解决方案无法正常工作。

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

不同的评论建议重新开始日食并进行清理和重建。

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 ++构建下单击设置

  3. 在在GCC C ++编译器中,单击其他。

  4. 在其他标志框中,将 -std = c ++ 11附加到令牌列表中。

  5. 单击应用,然后单击确定。

  1. Right click your project and click Properties
  2. Under C/C++ Build click Settings
  3. Under GCC C++ Compiler, click Miscellaneous
  4. In the Other Flags box, append "-std=c++11" to the list of tokens.
  5. Click Apply and OK

此时,您应该能够重建项目并使它运行。但是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 ++索引,然后单击重新-解决未解决的包含。

  1. Right click your project and click Properties
  2. Under C/C++ General click "Preprocessor Include Paths, Macros"
  3. Select the Providers tab
  4. There should be an item in the list that says something like "GCC Built in Compiler Settings". Select this entry.
  5. Uncheck the "Use global provider..." option
  6. Under the list there's an box that says "Command to get compiler specs." Append "-std=c++0x" to this.
  7. Move the "GCC Built in Compiler Settings" provider at the top of the list using the 'Move Up' button on the right.
  8. Click Apply and then OK.
  9. Back in your Eclipse workspace, select the Project Menu, C/C++ Index, and click "Re-resolve unresolved includes."

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

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