ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Why does ROS2 custom message colcon build give include file errors?

asked 2021-12-25 09:05:37 -0500

ajayvohra2005 gravatar image

updated 2021-12-25 11:32:18 -0500

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(<dependency> 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
edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2021-12-26 01:37:29 -0500

robustify gravatar image

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.

edit flag offensive delete link more


I had tried this before, except for std_msgs/Header instead of just Header. These steps work.

ajayvohra2005 gravatar image ajayvohra2005  ( 2021-12-26 08:22:47 -0500 )edit

answered 2021-12-25 17:07:40 -0500

ljaniec gravatar image

There you could find some hints. I didn't find any problems with your changes though.

Did you try to delete old build and install files and rebuild the whole workspace?

Header message is in the std_msgs package, do you have it in the dependencies? That's it: <depend>std_msgs</depend> in package.xml and find_package(std_msgs REQUIRED) in CMakeLists.txt?

edit flag offensive delete link more

Question Tools



Asked: 2021-12-25 09:05:37 -0500

Seen: 1,425 times

Last updated: Dec 26 '21