ROS2: How to use custom message in project where it's declared?

It’s true that most our message package are pure message packages and thus do not try to include/link against themselves. The trick here is that you need to use the macro rosidl_target_interfaces

rosidl_target_interfaces(MY_TARGET_NAME
      ${PROJECT_NAME} "rosidl_typesupport_cpp")

You can look at the composition demo CMake code for an example.

I agree that this is not well documented and that an addition to https://github.com/ros2/ros2/wiki/Defining-custom-interfaces-(msg-srv) would be valuable

5 Likes