ROS Resources: Documentation | Support | Discussion Forum | Service Status | Q&A answers.ros.org
Ask Your Question
6

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

Comments

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
10

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:

add_definitions(-std=c++11)

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

Comments

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
7

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

Comments

1

Also consult this: https://gcc.gnu.org/wiki/Cxx11AbiComp... 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

The deadline to submit a proposal to present at ROSCon 2017 is June 25, 2017. Submit yours now!

Question Tools

1 follower

Stats

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

Seen: 4,934 times

Last updated: Sep 01 '15