C++11 full support on Eclipse
Eclipse works with C+11 support (Indexer and such) just fine: both Juno and Kepler. The thing is that you have to let Eclipse know that you are going to compile with C++11 support. This is done by providing additional flag -std=c++11
to CDT GCC Builtin Compiler Settings
in C/C++ -> Build -> Settings -> Discovery [tab]
so it will read something like:
${COMMAND} -E -P -v -dD "${INPUTS}" -std=c++11
And that is all you have to do with Kepler/Juno to get C++11 code highlighted correctly.
Note, this is workspace-wide setting. You can do the same on per project basis if you don't want to set it in workspace.
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
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 do you enable C++11 syntax in Eclipse Neon?
- Right click on your project and click Properties
- Navigate to C/C++ General and Preprocessor Include Paths, Macros etc.
- Select the Providers tab, click on compiler settings row for the compiler you use.
- Add -std=c++11 to Command to get compiler specs.
- Apply changes.
Will look something like this:
${COMMAND} -E -P -v -dD "${INPUTS}" -std=c++11
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)
Related Topics
How to Print Utf-8 Strings to Std::Cout on Windows
Serializing and Deserializing JSON with Boost
When Have You Used C++ 'Mutable' Keyword
Copy a Streambuf's Contents to a String
Operator Overloading on Class Templates
Self-Sufficient Header Files in C/C++
Arduino Sprintf Float Not Formatting
Call Base Class Method from Derived Class Object
C++11 Implementation of Spinlock Using <Atomic>
Opencv Tracking Using Optical Flow
How Do Traits Classes Work and What Do They Do
How to Overload Unary Minus Operator in C++
Cannot Get Opencv to Compile Because of Undefined References
Should I Use Shared_Ptr or Unique_Ptr