Ask Your Question

get ros2 version in C++

asked 2019-11-01 16:46:52 -0600

galou gravatar image

Are there any #define to know which version of ROS2 I'm using in C++ source?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2019-11-02 23:26:47 -0600

Dirk Thomas gravatar image

There are no defines in C/C++ out of the box.

That being said if your package depends on ros_environment the following environment variables are set: ROS_VERSION (which is either 1 or 2), ROS_DISTRO (e.g. dashing or melodic), etc.

You can use either to set compiler definitions in your package to be used in conditionals.

If you need more fine grain control you can also use the exact version number of each dependency (e.g.

edit flag offensive delete link more

Your Answer

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

Add Answer

Question Tools



Asked: 2019-11-01 16:46:52 -0600

Seen: 201 times

Last updated: Nov 02 '19