Ask Your Question

What happens if I use c++ 17 features in my ros nodes?

asked 2020-01-09 05:31:12 -0600

max11gen gravatar image

In the ROS manual/wiki you can see, that ROS is only made for C++11. But what exactly does that mean? What happens if I just put add_compile_options(-std=c++17) in the CMakeLists.txt of my ROS-package and use C++17-features anyway? Specifically: Is it possible to use parallel std::for_each from C++17 in my ROS-nodes?

edit retag flag offensive close merge delete


In the ROS manual/wiki you can see

please always link to pages you are referring to. Right now we don't know what you "see" exactly.

gvdhoorn gravatar imagegvdhoorn ( 2020-01-09 06:36:08 -0600 )edit

@gvdhoorn I know, sorry. The thing was just, that I couldn't actually find where exactly I had read that, but I rather just had it in the back of my head.

max11gen gravatar imagemax11gen ( 2020-01-09 08:13:52 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2020-01-09 06:35:18 -0600

gvdhoorn gravatar image

ROS is only made for C++11

this is actually not really true.

For ROS 1: Melodic has lifted the max version to C++14 (see here).

For ROS 2: all ROS 2 versions target C++14 by default (see REP-2000, search for "Minimum language requirements").

What happens if I just put add_compile_options(-std=c++17) in the CMakeLists.txt of my ROS-package and use C++17-features anyway?

Nothing. It probably will just work, as long as your C++17 object code is ABI compatible with whatever libraries you are linking against.

In other words: you'll potentially run into the exact same problems you could have with ABI incompatibilities between libraries when not using ROS.

edit flag offensive delete link more


Thanks for your answer. But how can I find out, if the object code is ABI compatible after all? Will I get errors if the compatibility is not given, or can it happen that there will be just arbitrary, undefined behaviour occurring?

max11gen gravatar imagemax11gen ( 2020-01-09 08:12:36 -0600 )edit

Yes, could be linking errors, could also be SEGFAULTs. I can't give you a more definitive answer unfortunately.

As I wrote: there is nothing really ROS specific here. It's essentially plain C++.

From my own personal experience though: C++03 + C++11 was troublesome (std::string etc). C++11 and newer has not been a problem for me so far (ie: combining binary artefacts compiled with these different versions). But again: personal experience, so this is not a guarantee everything will work.

gvdhoorn gravatar imagegvdhoorn ( 2020-01-09 08:16:10 -0600 )edit

In addition to above-mentioned, you can also use the set_properties macro in CMakeLists to set cpp standards for specific targets only (where you know you need c++17 for example) within a package instead for the whole package as it is done with add_compile_options. Here is an example which applies the c++17 standard for a defined executable:

set_property(TARGET my_executable PROPERTY CXX_STANDARD 17)
pavel92 gravatar imagepavel92 ( 2020-01-09 08:58:10 -0600 )edit

@gvdhoorn Alright, thanks for your help!

max11gen gravatar imagemax11gen ( 2020-01-09 09:51:35 -0600 )edit

@pavel92 Great hint, thanks.

max11gen gravatar imagemax11gen ( 2020-01-09 09:51:57 -0600 )edit

I would use target_compile_features(..) with a meta-feature instead, but it depends on your CMake version whether that is available.

gvdhoorn gravatar imagegvdhoorn ( 2020-01-09 10:14:57 -0600 )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: 2020-01-09 05:31:12 -0600

Seen: 60 times

Last updated: Jan 09