如何在 Eclipse Juno/Kepler/Luna CDT 中启用 C + + 11?

编辑: 事实证明这并不是 Eclipse Kepler 特有的。我必须对 Eclipse Juno 使用相同的过程。问题是,在回答同样问题的其他帖子中似乎缺少步骤。

我正在使用 Eclipse Kepler for C + + ,我正在尝试使用 C + + 11并得到错误。当我编译时,我得到了错误

错误: 在 C + + 98模式中不允许使用基于范围的 for 循环

我已经按照邮局的指示做了

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

Eclipse Juno 给出的解决方案不起作用。

不同的评论建议重新开始日食和清洁和重建。这并没有什么不同。

88153 次浏览

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.)

Setting up the compiler is fairly straightforward:

  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

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. 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."

C++11 support in Eclipse Kepler Service Release 1 (Build id: 20130919-0819)

In the latest release Eclipse Kepler SR1 you only have to add -std=c++11

  1. Right click on your project and click Properties
  2. Navigate to C/C++ General and Preprocessor Include Paths, Macros etc.
  3. Select the Providers tab
  4. Add -std=c++11 to Command to get compiler specs:
  5. Apply changes, the Index should be generated automatically.

The "Command to get compiler specs:"-line should look like:

${COMMAND} -E -P -v -dD "${INPUTS}" -std=c++11

I use Eclipse Kepler and to fix it i did this:

1 - Right-Click the Project >> Proprietes >> C/C++ Build :: Settings

2 - Went to GCC G++ Compiler >> Miscellaneous >> Other Flags

I then added -std=c++11, hit apply and ok

That fixed my problem!

I hope this helps!

As of CDT 8.3 (available as a Kepler update), there is a new dialect option in build settings:

http://wiki.eclipse.org/CDT/User/NewIn83#Build

Running eclipse indigo and cdt 8.0.2 here. I followed all the guides, but it was still necessary to set the preprocessor define by hand to find things like std::unique_ptr. The include file "memory" checks this. Set __cplusplus to 201103L on the "Symbols" tab under "Paths and Symbols" in "C++ General" in project properties.

Adding dialect flag "-std=c++11" to Project properties-> C/C++ Build -> Settings -> Tool settings (GCC C++ Compiler -> Dialect) solved my problem in Eclipse Kepler, apart from the settings stated above.

I'm using Eclipse Luna and there is no "Tool Settings" under C/C++ Build -> Settings. I DID add -std=c++11 to the compiler specs command line under "C/C++ General -> Preprocessor Includes -> Providers" as suggested. But that still did not satisfy my indexer's ability to resolve emplace().

So I looked in the header file for and found that the emplace functions are dependent on __cplusplus >= 201103L. So I just added the preprocessor symbol "__cplusplus" and gave it the value 201103.

Kinda hackish but the indexer is happy. (And makefiles define my build flags, not the eclipse project)

The solution provided by MrEricSir only works after having the latest Eclipse Oxygen CDT installed. It doesn't work for me with Mars CDT.