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

Revision history [back]

It is possible to have msg/action/srv files in the same package as where you are using them, but the CMakeLists.txt is slightly different to the case where they are in separate packages.

The Expanding on ROS Interfaces (Foxy) covers this exact case.

Modify your CMakeLists.txt as following:

// Your existing code
install(TARGETS
  action_tutorials
  ARCHIVE DESTINATION lib
  LIBRARY DESTINATION lib
  RUNTIME DESTINATION bin)

// ---- Insert Folowing ----

// Humble onwards
rosidl_get_typesupport_target(cpp_typesupport_target ${PROJECT_NAME} "rosidl_typesupport_cpp")
target_link_libraries(action_tutorials "${cpp_typesupport_target}")

// Foxy, Galactic
rosidl_target_interfaces(action_tutorials ${PROJECT_NAME} "rosidl_typesupport_cpp")

// ---- Up to here ----

// Your existing code
if(BUILD_TESTING)
  find_package(ament_lint_auto REQUIRED)
  ament_lint_auto_find_test_dependencies()
endif()

For more info, see this solution:

https://robotics.stackexchange.com/questions/23171/creating-a-custom-msg-in-ros2