23

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.

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.

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)

Community
  • 1
  • 1
CPayne
  • 516
  • 2
  • 5
  • 20
  • 2
    FYI, on some computers (at least mine) Eclipse Neon parser works with C++14 by default. This is probbaly due to the fact that g++ 5.4.0 and later versions compile with C++14 support by default (like you would add command normally, I don't have to), hence Eclipse parser works without need to add -std=c++14 to providers tab. Conclusion: upgrading compiler can fix parser issue. – Xeverous Jan 29 '17 at 18:59

5 Answers5

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

Will look something like this:

${COMMAND} -E -P -v -dD "${INPUTS}" -std=c++11
CPayne
  • 516
  • 2
  • 5
  • 20
Andreas DM
  • 10,685
  • 6
  • 35
  • 62
  • 9
    FWIW I also had to rebuild the index (right click on your project->Index->Rebuild). – syntheticgio Jan 20 '17 at 15:41
  • I also had to do above steps for "All" build configuration. – V. Panchenko Jul 07 '17 at 07:09
  • 4
    this didn't work for me :( Instead I went to 1. Properties 2. C/C++ Build 3. Settings 4. Dialect 5. put -std=c++11 in Other dialect flags box 6. Apply and Build – Geronimo Nov 14 '17 at 15:08
  • After executing these steps. Project-> C/C++ index -> Freshen all files – ShahzadIftikhar Dec 05 '17 at 14:32
  • 2
    @Pavel re "having to [change enable c++11] for every project": you can change this setting globally for all eclipse c++ projects. Instead of modifying the configuration for only your project (via: "right click on your project")... instead edit the global configuration for all projects (via: opening the Eclipse menu --> Window --> Preferences --> C/C++ --> Build --> Settings --> Discovery --> "CDT GCC Build-in Compiler Settings" --> then append the `-std=c++11` or `-std=gnu++11` or `-std=gnu++0x`). – Trevor Boyd Smith Feb 12 '18 at 15:57
  • 2
    It's very important to rebuild the index! I spend half an hour trying to figure out why this solution doesn't work for me. Thank you so much @SyntheticGio – cesargastonec Mar 16 '18 at 11:13
7

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.

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.
mancini0
  • 4,285
  • 1
  • 29
  • 31
1

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.

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.

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.

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.

g++ is at version 7.2.1

bazza
  • 7,580
  • 15
  • 22
0

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

interestedparty333
  • 2,386
  • 1
  • 21
  • 35
0

If nothing above works for you: Just check if

Properties > C/C++ Build > Settings > Tool Settings tab > Dialect

Confirm if you have "ISO C++11 ..." option in Language standard drop-down Menu.

If yes then select > Apply and close.

I hope this will work.

Hridaynath
  • 497
  • 5
  • 4