ROS C++ dependencies missconception
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 ?
Asked by risbo6 on 2022-03-28 04:38:51 UTC
Answers
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.
Asked by gvdhoorn on 2022-03-29 03:17:05 UTC
Comments
Which dependency entries are you asking about: CMakeLists.txt or package.xml? They have different reasons to exist.
Asked by Mike Scheutzow on 2022-03-28 15:24:35 UTC