Eclipse, CMake and C++11

Getting C++11 to work with CMake is easy. Getting Eclipse to work with a CMake project is easy. Getting Eclipse to work with C++11 also seems to be relatively easy (there are plenty of guides on various wikis).

But getting all three to cooperate nicely is a bit trickier – or rather, the standard Eclipse way to configure C++11 support doesn’t work for CMake projects, and none of the guides I could find at first mentioned that.

It’s perfectly possible to work with a C++11 CMake project in Eclipse without any special settings. Compiling and running the code works fine (as the compiler gets its settings from the CMake config), but the code editor will keep mark various C++11 code bits as errors.

Fortunately, this Stack Overflow post shows how easy it is to fix this for Eclipse Kepler if you just know the right option to set. Simply create your Eclipse project with something like this:

cmake ../my_src_dir -G"Eclipse CDT4 - Unix Makefiles" -DCMAKE_ECLIPSE_VERSION=4.2 -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_COMPILER_ARG1=-std=c++11

The above is for a Linux Make project. For different platforms, change the -G option accordingly. The relevant bit is of course the CMAKE_CXX_COMPILER_ARG1 option.

This entry was posted in C++11, CMake, Eclipse and tagged , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *