Why does ROS2 custom message colcon build give include file errors?
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) project(tutorial_interfaces) if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") add_compile_options(-Wall -Wextra -Wpedantic) endif() # 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) rosidl_generate_interfaces(${PROJECT_NAME} "msg/Num.msg" "msg/Complex.msg" ) if(BUILD_TESTING) 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) ament_lint_auto_find_test_dependencies() endif() ament_package()
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