Enable C++11 in Eclipse CDT (Juno/Kepler/Luna) indexer
Note that this question (and answer) only deals with the Eclipse indexer which is used to highlight errors before compilation takes place. The C++ compiler settings are not changed! (Thus, compilation could still fail because of missing C++11 settings, but have a look at the "Related" section)
To change the Eclipse indexer settings go toProject properties
-> C/C++ General
-> Preprocessor Include Paths, Macros etc.
-> tab Providers
-> CDT GCC Built-in Compiler Settings
and append -std=c++0x
(or -std=c++11
) to Command to get compiler specs:
Afterwards it should look something like:
${COMMAND} -E -P -v -dD ${INPUTS} -std=c++0x
Sources
- http://wiki.eclipse.org/CDT/User/FAQ#CDT_does_not_recognize_C.2B.2B11_features
- http://www.eclipse.org/forums/index.php/mv/msg/373462/909018/#msg_909018
Related
- Eclipse CDT C++11/C++0x support
- https://stackoverflow.com/a/17499266/760746 (C++11-enable the compiler (Kepler and before))
- https://stackoverflow.com/a/22480299/760746 (C++11-enable the compiler (Kepler (updated) and newer)
Update
Successfully tested with Eclipse
- Kepler (CDT 8.2)
- Luna (CDT 8.4)
How to enable C++11 in Eclipse Juno/Kepler/Luna CDT?
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."
How to enable C++11/C++0x support in Eclipse CDT?
I found this article in the Eclipse forum, just followed those steps and it works for me. I am using Eclipse Indigo 20110615-0604 on Windows with a Cygwin setup.
- Make a new C++ project
- Default options for everything
- Once created, right-click the project and go to "Properties"
- C/C++ Build -> Settings -> Tool Settings -> GCC C++ Compiler -> Miscellaneous -> Other Flags. Put
-std=c++0x
(or for newer compiler version-std=c++11
at the end . ... instead of GCC C++ Compiler I have also Cygwin compiler - C/C++ General -> Paths and Symbols -> Symbols -> GNU C++. Click "Add..." and paste
__GXX_EXPERIMENTAL_CXX0X__
(ensure to append and prepend two underscores) into "Name" and leave "Value" blank. - Hit Apply, do whatever it asks you to do, then hit OK.
There is a description of this in the Eclipse FAQ now as well: Eclipse FAQ/C++11 Features.
Eclipse setting
Eclipse CDT enabling c++ 11 problems
After a lot of research, I solved this issue by downgrading the CDT plugin (was 8.1.2, d/g to 8.0.2).
Apperantly there were some compatibility issues.
Related Topics
How to Create My Own Comparator For a Map
How to Construct a Std::String With an Embedded Null
Std::Thread Pass by Reference Calls Copy Constructor
Default Value of Function Parameter
Can Placement New For Arrays Be Used in a Portable Way
C++ Vector Size. Why -1 Is Greater Than Zero
How to Implement a C++ Class in Python, to Be Called by C++
What's Your Favorite Profiling Tool (For C++)
Why Is Default Constructor Called in Virtual Inheritance
Compelling Examples of Custom C++ Allocators
Strict Aliasing Rule and 'Char *' Pointers
C++11 Allows In-Class Initialization of Non-Static and Non-Const Members. What Changed
Creating an Input Stream from Constant Memory
Can Standard Container Templates Be Instantiated With Incomplete Types