How to enable C++11 in Eclipse Juno/Kepler/Luna CDT?
Solution 1
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:
- Right click your project and click Properties
- Under C/C++ Build click Settings
- Under GCC C++ Compiler, click Miscellaneous
- In the Other Flags box, append "-std=c++11" to the list of tokens.
- 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:
- Right click your project and click Properties
- Under C/C++ General click "Preprocessor Include Paths, Macros"
- Select the Providers tab
- There should be an item in the list that says something like "GCC Built in Compiler Settings". Select this entry.
- Uncheck the "Use global provider..." option
- Under the list there's an box that says "Command to get compiler specs." Append "-std=c++0x" to this.
- Move the "GCC Built in Compiler Settings" provider at the top of the list using the 'Move Up' button on the right.
- Click Apply and then OK.
- Back in your Eclipse workspace, select the Project Menu, C/C++ Index, and click "Re-resolve unresolved includes."
Solution 2
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
- Right click on your project and click Properties
- Navigate to C/C++ General and Preprocessor Include Paths, Macros etc.
- Select the Providers tab
- Add -std=c++11 to Command to get compiler specs:
- 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
Solution 3
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
Solution 4
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!
Solution 5
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.
Related videos on Youtube
user327301
Updated on March 26, 2022Comments
-
user327301 over 2 years
EDIT: 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.
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
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 support
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.
-
user327301 almost 11 yearsThank you. This worked. Maybe I misread the other post I linked to, but it seems that there was no mention of setting up the compiler in that post.
-
Dolanor almost 11 yearsDoesn't work for me. My main problem is the unresolved c++11 includes. I put
-std=c++11
in where you said to put, and rebuilt the full index, still shows a crapload of unrecognized std::cout, std::set, etc… -
Dolanor almost 11 yearsEDIT: I didn't find the first part where it should, but I'm compiling through make, so it may be an explanation. (I found it in workspace configuration though and set it). But I put it in the
compiler spec
, and still doesn’t work. std::shared_ptr and same not recognized. Though it used to work on the older machine with juno. -
Denis Zaikin over 10 yearsIn my case(gcc) I used -std=c++0x. So everything is working. Thank you!
-
Rijndael over 10 yearsYou might need to restart eclipse if it doesn't work once you've made the changes.
-
TCSGrad over 10 yearsThis is the best answer for Eclipse Platform, Version: 4.3.1 - Don't know what Kepler/Juno is!
-
Ivaylo Strandjev about 10 years@MrEricSir is there a way to make this setting for workspace so that when I add a new project it is automatically applied to it too?
-
ccook almost 10 yearsWith GCC I had to add -std=c++0x
-
MeJ over 9 yearsWhich GCC do you use? c++0X was the old name (alias) for C++11
-
ccook over 9 yearsFound this a second time setting up a fresh eclipse CDT - setting this up should be more intuitive.
-
Guy L over 9 yearsYes, Works for migrations from old projects.
-
Ahmed Adel Ismail over 9 yearshave been searching for days, i'm a java developer and new to C++ and was stuck at this point, the tutorial is done with C++11 and Eclipse is stopping me, thanks alot ... and please if you have any links or resources that help me learn C++ (i'm heading to learn windows phone) please let me know ... thanks
-
MrEricSir over 9 years@EL-conteDe-monteTereBentikh Glad to hear I could help setting up your workspace, but I can't recommend any specific tutorials myself, nor would it be within StackOverflow's policies for me to do so. That said, you're lucky enough to learn computer programming in the information age -- try your favorite search engine, your local libraries and bookstores, or inquiring at colleges and universities.
-
Marco Massenzio about 9 yearsAnd this is why I stopped using Eclipse for all my other non-C++ development: honestly, does one really need all this grief, when a "Use C++11" checkbox in Preferences would suffice?
-
Scuba Steve almost 8 yearsGoddamn kepler moved the misc tab out of the settings window. Sometimes I love eclipse, and sometimes....
-
jwimberley about 7 years@ScubaSteve Do you know where they moved it to? I have Neon and I'm still looking...
-
Scuba Steve about 7 years@jwimberley - Honestly, unless you have to use a specific compiler, just use .Net and Visual Studio 2015. Eclipse is a sad joke by comparison.
-
Karrq over 6 yearsEclipse Kepler is Eclipse Version 4.3.X