ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A
Ask Your Question

[ROS2 Humble] Unable to compile custom srv which depends on msg

asked 2022-05-25 04:40:36 -0500

808brick gravatar image

updated 2022-05-25 04:51:53 -0500

Problem: Custom srv file will not compile if using a fieldtype that is a msg from a package on ROS2 Humble. It seems the __struct C/C++ dependencies are not properly being detected by colcon. The same srv file / package was able to compile on ROS2 Foxy without any errors.

OS: Ubuntu 22.04 x86

The custom srv file (TurnCamera.srv)

float32 deg_turn
sensor_msgs/Image camera_image

The error received when running colcon build:

In file included from /home/ray/Workspaces/ros2_cpp_ws/build/udemy_ros2_pkg/rosidl_generator_c/udemy_ros2_pkg/srv/detail/turn_camera__functions.h:19,
                 from /home/ray/Workspaces/ros2_cpp_ws/build/udemy_ros2_pkg/rosidl_generator_c/udemy_ros2_pkg/srv/detail/turn_camera__functions.c:4:
/home/ray/Workspaces/ros2_cpp_ws/build/udemy_ros2_pkg/rosidl_generator_c/udemy_ros2_pkg/srv/detail/turn_camera__struct.h:41:10: fatal error: sensor_msgs/msg/detail/image__struct.h: No such file or directory
   41 | #include "sensor_msgs/msg/detail/image__struct.h"
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
gmake[2]: *** [CMakeFiles/udemy_ros2_pkg__rosidl_generator_c.dir/build.make:135: CMakeFiles/udemy_ros2_pkg__rosidl_generator_c.dir/rosidl_generator_c/udemy_ros2_pkg/srv/detail/turn_camera__functions.c.o] Error 1
gmake[1]: *** [CMakeFiles/Makefile2:225: CMakeFiles/udemy_ros2_pkg__rosidl_generator_c.dir/all] Error 2
gmake[1]: *** Waiting for unfinished jobs....
gmake: *** [Makefile:146: all] Error 2

I tried compilation from the Debian installation of Humble as well as Rolling built from source.

At first glance I assumed it was a sensor_msgs dependency issue within either my CMakeLists.txt file or package.xml file. But the compilation on ROS2 Foxy (on a separate Ubuntu 20 x86 machine) worked fine with the same config, so I am wondering if extra commands are needed within the CMakeLists.txt file for the Humble distro for compilation?

For reference, the following SRV can compile successfully if not using a package message type as a field type such as:

float32 deg_turn
int64 camera_image

But I receive the same type of error for any other package / msg combo, including that of std_msgs. The following config fails to compile with the same issue:

float32 deg_turn
std_msgs/Int64 camera_image

Which returns this error:

/home/ray/Workspaces/ros2_cpp_ws/build/udemy_ros2_pkg/rosidl_generator_c/udemy_ros2_pkg/srv/detail/turn_camera__struct.h:41:10: fatal error: std_msgs/msg/detail/int64__struct.h: No such file or directory
   41 | #include "std_msgs/msg/detail/int64__struct.h"
/home/ray/Workspaces/ros2_cpp_ws/build/udemy_ros2_pkg/rosidl_generator_cpp/udemy_ros2_pkg/srv/detail/turn_camera__struct.hpp:134:10: fatal error: std_msgs/msg/detail/int64__struct.hpp: No such file or directory
      134 | #include "std_msgs/msg/detail/int64__struct.hpp"

But compiles just fine on Foxy. So has the way which msgs from other packages are included in custom SRV files from Humble forward changed? I had removed all nodes from compiling for the purposes of these tests, just to try and test the compilation of the custom srv. Basically any msg you try to use results in the C (and sometimes the C++) struct not being built for that msg.

Here are my other package files for reference:


<?xml version="1.0"?>
<?xml-model href="" schematypens=""?>
<package format="3">
  <version>0.0.0< ...
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2022-05-25 11:53:58 -0500

updated 2022-05-25 11:54:24 -0500

I am not sure how did it even build in Foxy, you are not passing the dependencies to rosidl_generate_interfaces.

You can see an example here

Basically you need to specify other msgs that your new custom msgs use;

  DEPENDENCIES builtin_interfaces geometry_msgs std_msgs sensor_msgs
edit flag offensive delete link more


Thank you for the response, your solution worked. Perhaps this is something that should be included in the ROS2 custom msg/srv tutorial page? I may try opening a pull request later this week.

808brick gravatar image 808brick  ( 2022-05-25 13:01:18 -0500 )edit

sure, I think people might run into that easily, so it will be good contribution to open PR

Fetullah Atas gravatar image Fetullah Atas  ( 2022-05-25 13:38:07 -0500 )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



Asked: 2022-05-25 04:40:36 -0500

Seen: 514 times

Last updated: May 25 '22