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

Problem with service call.

asked 2022-10-30 09:28:58 -0600

Edvard gravatar image

updated 2022-10-30 22:18:25 -0600

Hi. Sorry for all mistakes, English is not my native language. I am porting my project from ros1 to ros2 and I have following error:

/usr/bin/ld: CMakeFiles/minicar_control_node.dir/src/control_node.cpp.o: in function `main':
control_node.cpp:(.text+0x8a4): undefined reference to `minicar::LoopbackRobotHWSim::LoopbackRobotHWSim()'
/usr/bin/ld: control_node.cpp:(.text+0xa8a): undefined reference to `minicar::STMRobotHW::STMRobotHW()'
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/minicar_control_node.dir/build.make:1039: minicar_control_node] Error 1
make[1]: *** [CMakeFiles/Makefile2:439: CMakeFiles/minicar_control_node.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
/usr/bin/ld: CMakeFiles/cmd_vel_limiter.dir/src/cmd_vel_limiter_node.cpp.o: in function
`rclcpp::Service<std_srvs::srv::SetBool>::Service(std::shared_ptr<rcl_node_t>, 
std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, 
rclcpp::AnyServiceCallback<std_srvs::srv::SetBool>, rcl_service_options_t&)':
cmd_vel_limiter_node.cpp:(.text._ZN6rclcpp7ServiceIN8std_srvs3srv7
SetBoolEEC2ESt10shared_ptrI10rcl_node_tERKNSt7_
_cxx1112basic_stringIcSt11char_traitsIcESaIcEEENS_18AnyServiceCallback
IS3_EER21rcl_service_options_t[_ZN6rclcpp7
ServiceIN8std_srvs3srv7SetBoolEEC5ESt10shared_ptrI10rcl_node
_tERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEENS
_18AnyServiceCallbackIS3_EER21rcl_service_options_t]+0xb4): 
undefined reference to `rosidl_service_type_support_t 
const* rosidl_typesupport_cpp::get_service_type_support_handle<std_srvs::srv::SetBool>()'
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/cmd_vel_limiter.dir/build.make:1039: cmd_vel_limiter] Error 1
make[1]: *** [CMakeFiles/Makefile2:525: CMakeFiles/cmd_vel_limiter.dir/all] Error 2
make: *** [Makefile:141: all] Error 2
--- stderr: minicar_control                             
/usr/bin/ld: CMakeFiles/minicar_control_node.dir/src/control_node.cpp.o: in function `main':
control_node.cpp:(.text+0x8a4): 
undefined reference to `minicar::LoopbackRobotHWSim::LoopbackRobotHWSim()'
/usr/bin/ld: control_node.cpp:(.text+0xa8a): 
undefined reference to `minicar::STMRobotHW::STMRobotHW()'
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/minicar_control_node.dir/build.make:1039: minicar_control_node] Error 1
make[1]: *** [CMakeFiles/Makefile2:439: CMakeFiles/minicar_control_node.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
/usr/bin/ld: CMakeFiles/cmd_vel_limiter.dir/src/cmd_vel_limiter_node.cpp.o: 
in function `rclcpp::Service<std_srvs::srv::SetBool>::
Service(std::shared_ptr<rcl_node_t>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > 
const&, rclcpp::AnyServiceCallback<std_srvs::srv::SetBool>, rcl_service_options_t&)':
cmd_vel_limiter_node.cpp:(.text._ZN6rclcpp7ServiceIN8std_srvs3srv7SetBoolEEC2ESt10shared_ptrI10rcl_node_tERKNSt7__
cxx1112basic_stringIcSt11char_traitsIcESaIcEEENS_18AnyServiceCallbackIS3_EER21rcl_service_options_t[_ZN6rclcpp7
ServiceIN8std_srvs3srv7SetBoolEEC5ESt10shared_ptrI10rcl_node_tERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEENS
_18AnyServiceCallbackIS3_EER21rcl_service_options_t]+0xb4): undefined reference to `rosidl_service_type_support_t const* rosidl_typesupport_cpp::get_service_type_support_handle<std_srvs::srv::SetBool>()'
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/cmd_vel_limiter.dir/build.make:1039: cmd_vel_limiter] Error 1
make[1]: *** [CMakeFiles/Makefile2:525: CMakeFiles/cmd_vel_limiter.dir/all] Error 2
make: *** [Makefile:141: all] Error 2

This is how looks create_service lines looks like:

rclcpp::Service<std_srvs::srv::SetBool>::SharedPtr srv_enableLimiter = pNodeHandle->create_service<std_srvs::srv::SetBool>("/minicar/control/enable_limiter", &EnableLimiterService);

EnableLimiterService method constructor:

bool EnableLimiterService(const std::shared_ptr<std_srvs::srv::SetBool::Request> request, std::shared_ptr<std_srvs::srv::SetBool::Response> response);

This is CMakeLists.txt: cmake_minimum_required(VERSION 3.5) project(minicar_control)

# Add support for C++14
if(NOT CMAKE_CXX_STANDARD)
  set(CMAKE_CXX_STANDARD 14)
endif()

# Load catkin and all dependencies required for this package

link_directories(${catkin_LIBRARY_DIRS})

## Restrict Windows header namespace usage
if(WIN32)
  add_definitions(-DNOGDI)
endif()

add_library(minicar_hw_interface src/loopback_hw_interface.cpp
  src/stm_hw_interface.cpp src/base_hw_interface.cpp)

add_executable(minicar_control_node src/control_node.cpp)

add_executable(cmd_vel_limiter src/cmd_vel_limiter_node.cpp)

find_package(ament_cmake REQUIRED)
find_package(std_srvs REQUIRED)
find_package(angles REQUIRED)
find_package(controller_manager REQUIRED)
find_package(transmission_interface REQUIRED)
find_package(pluginlib REQUIRED)
find_package(urdf REQUIRED)
find_package(control_toolbox REQUIRED)
find_package(rclcpp REQUIRED)
find_package(std_msgs REQUIRED)
find_package(hardware_interface REQUIRED)
find_package(rosidl_default_generators REQUIRED)
set(INCLUDE_DIRS ${ament_cmake_INCLUDE_DIRS} ${angles_INCLUDE_DIRS}
  ${controller_manager_INCLUDE_DIRS} ${transmission_interface_INCLUDE_DIRS}
  ${pluginlib_INCLUDE_DIRS} 
  ${urdf_INCLUDE_DIRS} ${control_toolbox_INCLUDE_DIRS} ${rclcpp_INCLUDE_DIRS}
  ${std_msgs_INCLUDE_DIRS} ${hardware_interface_INCLUDE_DIRS}
  ${rosidl_default_generators_INCLUDE_DIRS})
include_directories(${INCLUDE_DIRS})
set(LIBRARY_DIRS ...
(more)
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2022-10-31 03:04:18 -0600

Edvard gravatar image

I managed to solve this problem. Here is all things that I done in CMakeLists.txt:

  • add find_package(std_srvs REQUIRED)
  • add ament_target_dependencies(your_node_name rclcpp std_srvs)
  • add ament_export_dependencies(std_srvs) (not sure if that line is necessary but it works now for me)

In package.xml file:

  • add build_depend std_srvs
  • add exec_depend std_srvs
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2022-10-30 09:28:58 -0600

Seen: 186 times

Last updated: Oct 31 '22