Rosanswers logo

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="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="3">
  <maintainer email="[email protected]">ray</maintainer>
  <license>TODO: License declaration</license>







cmake_minimum_required(VERSION 3.8)

  add_compile_options(-Wall -Wextra -Wpedantic)

# find dependencies
find_package(ament_cmake REQUIRED)
find_package(rclcpp REQUIRED)
find_package(std_msgs REQUIRED)
find_package(rosidl_default_generators REQUIRED)
find_package(sensor_msgs REQUIRED)

# Generate custom interfaces

  find_package(ament_lint_auto REQUIRED)
  set(ament_cmake_copyright_FOUND TRUE)
  set(ament_cmake_cpplint_FOUND TRUE)


Any help would be greatly appreciated.

Originally posted by 808brick on ROS Answers with karma: 153 on 2022-05-25

Post score: 2


1 Answer 1


Rosanswers logo

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

Originally posted by Fetullah Atas with karma: 819 on 2022-05-25

This answer was ACCEPTED on the original site

Post score: 1

Original comments

Comment by 808brick on 2022-05-25:
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.

Comment by Fetullah Atas on 2022-05-25:
sure, I think people might run into that easily, so it will be good contribution to open PR


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.