ROS Resources: Documentation | Support | Discussion Forum | Service Status | Q&A
Ask Your Question

ROS using C++ 11 & How to Use With Catkin?

asked 2015-08-31 23:20:33 -0500

Rud gravatar image

Is ROS compiled using c++ 11 with catkin? I suspect not since I am getting an error trying to use {} initializer for a vector, i.e. c++98...must be initialized...

For at least my builds where in the catkin files would I add the '-std=c++11' option?

I am using Eclipse but I think this is controlled via the cmake files, not a project property.

edit retag flag offensive close merge delete


I poked around and found that adding the "-std-c++11" in the file flags.make worked. But I suspect it will be overwritten the next time I add a file to the CMakeLists.txt. Just wanted to mention this with the warning. The file was overwritten with the changes to the C*.txt file.

Rud gravatar imageRud ( 2015-09-01 23:51:45 -0500 )edit

Both answers provided worked. I flagged the one by Julius as 'correct' since it was more succinct. I added the line to just below the ## Build ## box, just fyi. Appreciated also the link to ROS/C++11 points.

Rud gravatar imageRud ( 2015-09-01 23:57:44 -0500 )edit

2 answers

Sort by ยป oldest newest most voted

answered 2015-09-01 00:55:34 -0500

JuliusGel gravatar image

All the current distributions of ROS are compiled using C++03.

You can compile your own packages using c++11 by adding the following line to the CMakeLists.txt of your project:


Note that it is recomended to have checks for c++11 features at configure time and provide equivalent functionality with extra compiler features. This is only required if you are planning to release the ROS packages that you develop. If you are only planning to use your packages yourself then you can just c++11 functionality. You can read more about ROS and C++11 here: link text

edit flag offensive delete link more


Thanks for the answer. I am at the moment only developing for myself. It will be awhile before I would attempt adding to ROS itself.

Rud gravatar imageRud ( 2015-09-01 23:47:55 -0500 )edit

Worked like a charm for me too. Thanks!

marcozorzi gravatar imagemarcozorzi ( 2016-06-02 03:27:49 -0500 )edit

answered 2015-09-01 01:33:49 -0500

You have to add

set(CMAKE_CXX_FLAGS "-std=c++11 ${CMAKE_CXX_FLAGS}")

to the CMakeLists.txt of your package.

edit flag offensive delete link more



Also consult this: Not sure if ROS is compiled to be ABI compatible between C++ versions.

dornhege gravatar imagedornhege ( 2015-09-01 06:01:20 -0500 )edit

Thanks for the answer.

Rud gravatar imageRud ( 2015-09-01 23:48:21 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2015-08-31 23:20:33 -0500

Seen: 3,607 times

Last updated: Sep 01 '15