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

ROS2 symlinks and SHARED libraries

asked 2022-03-26 10:48:04 -0500

updated 2022-03-28 17:26:47 -0500

I have a class named move_bb8 that I am using as SHARED library. I am linking it with my node move_bb8_node. If I build it without --symlink-install, I do not get any compilation error, but my node gives an error saying that it can not find the library

Here is my CMakeLists.txt

 # Define our move_bb8 class as library target 
add_library(move_bb8 SHARED 
ament_target_dependencies(move_bb8 rclcpp std_msgs geometry_msgs)

# Create an executable target for move_bb8_node and link it with our library move_bb8
add_executable(move_bb8_node src/move_bb8_node.cpp)
ament_target_dependencies(move_bb8_node rclcpp std_msgs geometry_msgs)
target_link_libraries(move_bb8_node move_bb8)

Can someone explain me the relationship between SHARED libraries and --symlink-install. I read the colcon documentation for --symlink-install, but it is still not clear to me.

Thank you!

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2022-11-15 04:24:19 -0500

This has to do with how your system dynamically loads the shared library. On linux, this is handled by ld, which looks for libraries in predefined paths. When using CMake to build your executable its RUNPATH is different from when installing it.

Quote from here:

Different RPATH settings may be required when running a program from the build tree and when running it from its install location.

Now, to put it in context with ROS, you can imagine that when invoking colcon to use symlink install the executable is no longer copied to the install directory. Instead, a link is created to the build folder executable.

You can check the executable runpath by

readelf -d <executable>

Hope this helps a little.

edit flag offensive delete link more

Question Tools



Asked: 2022-03-26 10:48:04 -0500

Seen: 455 times

Last updated: Mar 26 '22