c++cmakeincluderos2

Include a library in cmake_ament package


Taking this example from ROS2 official documentation, i want to add a library to one of the cmake_ament build packages.

In the example, they already included the string library

#include std_msgs/msg/string.hpp

for :

auto message = std_msgs::msg::String();

//and other manipulations

My task is to add a similar existing library to manipulate UInt64 types. I found it here.

My lazy try was to #include std_msgs/msg/string.hpp mimicking the example, after building, i got the error :

fatal error: std_msgs/msg/uint64.msg: No such file or directory
   22 | #include "std_msgs/msg/uint64.msg"
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~

So, i'm asking for working ways to manage it.

My CmakeLists.txt contains :

find_package(std_msgs REQUIRED)
ament_target_dependencies(talker rclcpp std_msgs)
ament_target_dependencies(listener rclcpp std_msgs)

Solution

  • .msg is wrong. You have to use #include "std_msgs/msg/uint64.hpp" or "std_msgs/msg/uint64.h"