Rosanswers logo

I am new to ROS2, but very familiar with ROS1.

I am doing a very minor tweak of the ROS2 tutorial Creating custom ROS 2 msg and srv files and it fails to build. The base tutorial code works fine. I don't care about srv so I got rid of that. And I added a new message.

The new message I added is named Complex.msg, and is shown below

Header header
Num num 

My CMakeLists.txt is as follows:

cmake_minimum_required(VERSION 3.8)

  add_compile_options(-Wall -Wextra -Wpedantic)

# find dependencies
find_package(ament_cmake REQUIRED)
# uncomment the following section in order to fill in
# further dependencies manually.
# find_package( REQUIRED)

find_package(rosidl_default_generators REQUIRED)


  find_package(ament_lint_auto REQUIRED)
  # the following line skips the linter which checks for copyrights
  # uncomment the line when a copyright and license is not present in all source files
  #set(ament_cmake_copyright_FOUND TRUE)
  # the following line skips cpplint (only works in a git repo)
  # uncomment the line when this package is not in a git repo
  #set(ament_cmake_cpplint_FOUND TRUE)


And my package.xml is unchanged from default shown in the ROS2 galactic tutorial.

When I try to build this slightly tweaked tutorial I get build errors shown below. I suspect that my new message requires changes to CMakeLists.txt and/or package.xml. If so, can you please guide what changes I need.

Colcon build error

colcon build --packages-select tutorial_interfaces

Starting >>> tutorial_interfaces
--- stderr: tutorial_interfaces                             
In file included from .../colcon_ws/build/tutorial_interfaces/rosidl_generator_c/tutorial_interfaces/msg/detail/complex__functions.h:19,
                 from .../colcon_ws/build/tutorial_interfaces/rosidl_generator_c/tutorial_interfaces/msg/detail/complex__functions.c:4:
.../colcon_ws/build/tutorial_interfaces/rosidl_generator_c/tutorial_interfaces/msg/detail/complex__struct.h:22:10: fatal error: tutorial_interfaces/msg/detail/header__struct.h: No such file or directory
   22 | #include "tutorial_interfaces/msg/detail/header__struct.h"
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.

...More errors like above

Summary: 0 packages finished [3.30s]
  1 package failed: tutorial_interfaces
  1 package had stderr output: tutorial_interface

Originally posted by ajayvohra2005 on ROS Answers with karma: 32 on 2021-12-25

Post score: 0


1 Answer 1


Rosanswers logo

I think you're missing a few things compared to a similar messages package I got working:

  • find_package for std_msgs where the header field comes from
  • DEPENDENCIES std_msgs in the rosidl_generate_interfaces command (see here)
  • Put std_msgs/Header in the .msg file instead of just Header

The relevant piece of your CMakeLists should be then:

find_package(rosidl_default_generators REQUIRED)
find_package(std_msgs REQUIRED)


Then, also put <depend>std_msgs</depend> in package.xml if you haven't already.

Originally posted by robustify with karma: 956 on 2021-12-26

This answer was ACCEPTED on the original site

Post score: 2

Original comments

Comment by ajayvohra2005 on 2021-12-26:
I had tried this before, except for std_msgs/Header instead of just Header. These steps work.


Your Answer

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