ROS2 Crystal member service linking rosidl_typesupport_cpp
Hi everyone,
I have a problem including services in ROS2 crystal packages. If I try to add and generate a custom service and use std service "Trigger", I get a rosidl linking error:
Error parsing
librobot_manager_lib.so: undefined reference to `rosidl_service_type_support_t const* rosidl_typesupport_cpp::get_service_type_support_handle<std_srvs::srv::trigger>()'
The service handle routine is implemented in the library lib.cpp and linked to the executable defined in test_node.cpp.
The package.xml looks like this:
<?xml version="1.0"?>
<?xml-model href="http://download.ros.org/schema/package_format2.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="3">
<name>test</name>
...
<buildtool_depend>ament_cmake</buildtool_depend>
<buildtool_depend>rosidl_default_generators</buildtool_depend>
<build_depend>ament_index_cpp</build_depend>
<build_depend>class_loader</build_depend>
<build_depend>rosidl_cmake</build_depend>
<build_depend>std_msgs</build_depend>
<build_depend>std_srvs</build_depend>
<build_depend>builtin_interfaces</build_depend>
<exec_depend>ament_index_cpp</exec_depend>
<exec_depend>class_loader</exec_depend>
<exec_depend>rclcpp</exec_depend>
<exec_depend>rosidl_default_runtime</exec_depend>
<exec_depend>std_msgs</exec_depend>
<exec_depend>std_srvs</exec_depend>
<exec_depend>builtin_interfaces</exec_depend>
<member_of_group>rosidl_interface_packages</member_of_group>
<export>
<build_type>ament_cmake</build_type>
</export>
</package>
And the CMakeLists.txt accordingly:
cmake_minimum_required(VERSION 3.5)
project(test)
#Load required packages
find_package(ament_cmake REQUIRED)
find_package(ament_index_cpp REQUIRED)
find_package(rcutils REQUIRED)
find_package(rclcpp REQUIRED)
find_package(std_msgs REQUIRED)
#Build Messages/Services 1
find_package(rosidl_default_generators REQUIRED)
rosidl_generate_interfaces(${PROJECT_NAME}
"srv/TestService.srv"
)
#Define the search space for the headers
include_directories(include)
#Build project library
add_library(${PROJECT_NAME}_lib SHARED src/lib.cpp)
ament_target_dependencies(${PROJECT_NAME}_lib rclcpp std_msgs rcutils class_loader)
rosidl_target_interfaces(${PROJECT_NAME}_lib ${PROJECT_NAME} "rosidl_typesupport_cpp") #Install srv hpp
install(TARGETS
${PROJECT_NAME}_lib
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin)
#Build&Install executable
add_executable(${PROJECT_NAME}_node src/test_node.cpp)
target_link_libraries(${PROJECT_NAME}_node ${PROJECT_NAME}_lib)
ament_target_dependencies(${PROJECT_NAME}_node rclcpp std_msgs rcutils class_loader)
#Install executable
install(TARGETS
${PROJECT_NAME}_node
DESTINATION lib/${PROJECT_NAME})
ament_export_dependencies(rosidl_default_runtime)
ament_package()
Do you have any idea what link I am missing here? Thanks a lot!