如何在 Eclipse Neon 中启用 C++11 语法?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/39134872/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 14:48:57  来源:igfitidea点击:

How do you enable C++11 syntax in Eclipse Neon?

c++eclipsec++11eclipse-neon

提问by CPayne

I am developing C+11 code in Eclipse Neon and noticed today that the range based for loop introduced in C+11 is highlighted red by the IDE indicating it does not recognize it.

我正在 Eclipse Neon 中开发 C+11 代码,今天注意到 C+11 中引入的基于范围的 for 循环被 IDE 突出显示为红色,表明它无法识别它。

I have found multiple links about how to do this for older versions of CDT such as this (Eclipse CDT C++11/C++0x support) You can see though there is no "Tool Settings" tab.

我找到了多个关于如何为旧版本的 CDT 执行此操作的链接,例如(Eclipse CDT C++11/C++0x 支持)您可以看到虽然没有“工具设置”选项卡。

enter image description here

在此处输入图片说明

Can someone suggest how to configure my project so that C++11 syntax is correctly highlighted (I am using a separate build system)

有人可以建议如何配置我的项目,以便正确突出显示 C++11 语法(我使用的是单独的构建系统)

回答by Andreas DM

  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, click on compiler settings row for the compiler you use.
  4. Add -std=c++11 to Command to get compiler specs.
  5. Apply changes.
  1. 右键单击您的项目,然后单击属性
  2. 导航到 C/C++ General 和 Preprocessor Include Paths、Macros 等。
  3. 选择 Providers 选项卡,单击您使用的编译器的编译器设置行。
  4. 将 -std=c++11 添加到 Command 以获取编译器规范。
  5. 应用更改。

Will look something like this:

看起来像这样:

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

回答by mancini0

You can also do the following

您还可以执行以下操作

  1. go to project properties (alt enter)
  2. In the left pane, scroll to "C/C++ Build", collapse it, select settings.
  3. In the right pane, select and collapse your compiler under the Tool Settings menu, select"Dialect", choose your languange standard from the drop down, or enter -std=c++11 in the "other dialect flags" text input.
  1. 转到项目属性(Alt Enter)
  2. 在左窗格中,滚动到“C/C++ Build”,折叠它,选择设置。
  3. 在右侧窗格中,在“工具设置”菜单下选择并折叠您的编译器,选择“方言”,从下拉列表中选择您的语言标准,或在“其他方言标志”文本输入中输入 -std=c++11。

Alternatively,

或者,

  1. Properties --> "C/C++ Build" --> collapse and and select "Settings"
  2. Under the Tool settings tab, select your compiler, and highlight the "Miscellaneous" field.
  3. add -std=c++11 to the "Other flags" input field.
  1. 属性 --> "C/C++ Build" --> 折叠并选择"设置"
  2. 在工具设置选项卡下,选择您的编译器,并突出显示“杂项”字段。
  3. 将 -std=c++11 添加到“其他标志”输入字段。

回答by bazza

For reasons I do not understand, when searching for clues as to why my Eclispe Oxygen + CDT 9.3.2 running on Fedora 27 could not reliably debug my code, Google put up this question / answer as something to look at.

出于我不明白的原因,在寻找有关为什么我在 Fedora 27 上运行的 Eclispe Oxygen + CDT 9.3.2 无法可靠地调试我的代码的线索时,Google 将此问题/答案作为要查看的内容。

Basically my problem has been that a fairly simply C++ program, using C++ 11 features (specifically shared_ptr), was un-debuggable in Eclipse Oxygen 2 + CDT 9.3.2 on top of Fedora 27 (which has gdb version 8.0.1 installed from the standard package repo). Stepping into a few method calls resulted in a hung debug session, nothing going on, terminate Eclipse to recover.

基本上我的问题是,一个相当简单的 C++ 程序,使用 C++ 11 特性(特别是 shared_ptr),在 Fedora 27 之上的 Eclipse Oxygen 2 + CDT 9.3.2 中是不可调试的(它安装了 gdb 8.0.1 版)标准包回购)。进入几个方法调用导致调试会话挂起,什么也没有发生,终止 Eclipse 以恢复。

If I debugged the binary using gdb on the command line, all was good; I could set break points, etc, everything worked as it should. But from inside Eclipse, nothing doing.

如果我在命令行上使用 gdb 调试二进制文件,一切都很好;我可以设置断点等,一切正常。但是从 Eclipse 内部,什么都不做。

However, putting -std=c++11 into the project settings as shown by Andreas solved the problem. I have very little idea why. I thought I'd put this up in case someone else ran into a similar problem.

但是,将 -std=c++11 放入 Andreas 所示的项目设置中解决了问题。我不知道为什么。我想我会提出来以防其他人遇到类似的问题。

g++ is at version 7.2.1

g++ 版本为 7.2.1

回答by ragerdl

For some reason editing the global c++ compiler settings didn't work for me. Following the instructions to modify the project-specific setting did work. See: Eclipse CDT C++11/C++0x support

出于某种原因,编辑全局 C++ 编译器设置对我不起作用。按照说明修改特定于项目的设置确实有效。请参阅:Eclipse CDT C++11/C++0x 支持