I am migrating a project from ROS1 to ROS2, I haven't created the project myself. In the main package, which is named 'rdds_kem123_test_package', there is a custom message which is an array of point clouds. This custom message is defined in the msg folder in the package. here is how the custom message file is written:

# ArrayPointCloud2.msg
std_msgs/Header header
sensor_msgs/PointCloud2[] cloud_array

In the CMakeLists file I have included the necessary things for the message:

cmake_minimum_required(VERSION 3.5)

# Compile as C++14, supported in ROS2

# Find ament macros and libraries
find_package(ament_cmake REQUIRED)
find_package(ament_cmake_python REQUIRED) 
find_package(rclcpp REQUIRED)
find_package(rclpy REQUIRED)
find_package(std_msgs REQUIRED)
find_package(rosidl_default_generators REQUIRED)
find_package(geometry_msgs REQUIRED)
find_package(sensor_msgs REQUIRED)
find_package(tf2 REQUIRED)
find_package(tf2_ros REQUIRED)
find_package(tf2_msgs REQUIRED)
find_package(tf2_sensor_msgs REQUIRED)
find_package(PCL REQUIRED COMPONENTS common io) # For pcl_conversions and pcl_ros



  DEPENDENCIES std_msgs sensor_msgs

#including the C++ include directory 

add_executable(pcl_merge src/pcl_merge.cpp)
ament_target_dependencies(pcl_merge rclcpp std_msgs geometry_msgs sensor_msgs tf2 tf2_ros tf2_msgs tf2_sensor_msgs PCL)
target_link_libraries(pcl_merge ${PCL_LIBRARIES})
# the rest is adding executables in the same way as this and then installing them. 

In the package.xml file, I believe I am including the necessary dependencies as well:



Then in one of my C++ scripts I try to include the header file of the custom message to use it to publish an array of point clouds, here is a part of that file:

#include <rclcpp/rclcpp.hpp>
#include <sensor_msgs/msg/point_cloud2.hpp>
#include <rdds_kem123_test_package/ArrayPointCloud2.h>
#include <pcl_conversions/pcl_conversions.h>
#include <pcl/point_cloud.h>
#include <pcl/point_types.h>

#Some code goes here and I call the custome message like the following 

//Custom message to store the clusters as individual clouds
rdds_kem123_test_package::ArrayPointCloud2 OutputClusters;

Everytime I try to build the package, I reach a 87% build and then it gives me the following error:

ros@ros:~/test_mig_ws$ colcon build --packages-select rdds_kem123_test_package Starting >>> rdds_kem123_test_package --- stderr: rdds_kem123_test_package
In file included from /home/ros/test_mig_ws/src/rdds_kem123_test_package/src/clustering.cpp:33: /home/ros/test_mig_ws/src/rdds_kem123_test_package/include/rdds_kem123_test_package/clustering.hpp:6:10: fatal error: rdds_kem123_test_package/ArrayPointCloud2.h: No such file or directory 6 | #include <rdds_kem123_test_package/ArrayPointCloud2.h> | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ compilation terminated.

One solution that I tried is to create a different package in the same workspace for interfaces, and I defined the custom message in it. The interfaces message built successfully without probelms, but then when I tried to include it again in the C++ script in the main package, it gave the same error as the following:

enter image description here

My understanding is that this header file should be created automatically by the building of the packages. ROS should create the source code needed for this custom message. I am not sure if I understand everything correctly, but I would really appreciate the help with this.

Thank you.


2 Answers 2


Have you added the new interfaces package to your ament_target_dependencies?

This is how my CMakeLists.txt looks like for a cpp executable:

find_package(reconstruction_msgs REQUIRED)

# Executables ------------------------------
ament_target_dependencies( gp25_services_node

The custom interface package in my case is the reconstruction_msgs.

Also make sure your #include ends with .hpp.

  • $\begingroup$ Yes I have added the needed changes to both files, similar to what you have as well, but I am still seeing the same error. $\endgroup$ Commented Apr 9 at 7:31
  • $\begingroup$ The file you found in the other answer (with the lowercase naming) is the right one: #include <rdds_kem123_test_package/msg/array_point_cloud2.hpp> should point include the right msg type $\endgroup$
    – mink4sure
    Commented Apr 9 at 7:44
  • $\begingroup$ Yes, Thank you, for some reason the name has changed to lower case with underscores, which i did not expect, and now when I compile that, I do not receive this error anymore. $\endgroup$ Commented Apr 9 at 11:28

I believe that you would find the header file in a msg directory inside of the install folder so your include statement should actually be:

#include <rdds_kem123_test_package/msg/ArrayPointCloud2.hpp>

If you want to have the interfaces are defined in a separate ROS package for example rdds_kem123_interfaces. The rdds_kem123_test_package would need these changes:

find_package(rdds_kem123_interfaces REQUIRED)


ament_target_dependencies(pcl_merge rclcpp std_msgs geometry_msgs sensor_msgs tf2 tf2_ros tf2_msgs tf2_sensor_msgs PCL rdds_kem123_interfaces)
Manifest (package.xml)
  • $\begingroup$ Thank you @Justin, yes, I am focusing on the interfaces packages approach right now, I added the required CMakeLists and package.xml changes. and I am still getting the same error. But because of your comment about finding it in the install folder, I went there to test_mig_ws/install/ysio_interfaces/include/ysio_interfaces/msg , I found a header file that is called 'array_point_cloud2.hpp" and 'array_point_cloud2.h' (Original name: ArrayPointCloud2), when I try to include it with this different name, i get so many other errors in my folder, so I am not sure if this is the right thing. $\endgroup$ Commented Apr 9 at 7:31

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.