ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

ROS C++ dependencies missconception

asked 2022-03-28 04:38:51 -0500

risbo6 gravatar image

updated 2022-03-28 04:39:58 -0500

Hey,

I've created a package with only a roscpp dependencies using :

catkin_create_pkg my_package roscpp

On my script, I'm using a Twist message, so I've added :

#include <geometry_msgs/Twist.h>

It works fine and that's the problem... Why does it work since I've not added the std_msgs nor the geometry_msgs dependency? Is this just optional ?

edit retag flag offensive close merge delete

Comments

Which dependency entries are you asking about: CMakeLists.txt or package.xml? They have different reasons to exist.

Mike Scheutzow gravatar image Mike Scheutzow  ( 2022-03-28 15:24:35 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2022-03-29 03:17:05 -0500

gvdhoorn gravatar image

updated 2022-03-29 03:17:32 -0500

This likely "works" because geometry_msgs will be installed with a regular ROS 1 installation.

So even if you don't add geometry_msgs as a (build) dependency to your CMakeLists.txt and package.xml, /opt/ros/$ROS_DISTRO/include will end up on the include path of your compiler/preprocessor (as part of the include paths exported by some other package you (transitively) depend on), and it will be able to resolve geometry_msgs/Twist.h to /opt/ros/$ROS_DISTRO/include/geometry_msgs/Twist.h.

Now you could ask: "if this works, then why bother adding (build) dependencies to packages at all?"

The answer would be: because you cannot rely on packages like geometry_msgs to always already have been installed.

A ROS 1 installation without geometry_msgs would be perfectly possible, and in that case, when someone tries to build your package, it would fail, as you've not made the dependency on geometry_msgs explicit, and it will not be detected to be missing before the build is started.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2022-03-28 04:38:51 -0500

Seen: 84 times

Last updated: Mar 29 '22