ROS2 symlinks and SHARED libraries
I have a class named move_bb8 that I am using as SHARED library. I am linking it with my node movebb8node. 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 move_bb8.so.
Here is my CMakeLists.txt
# Define our move_bb8 class as library target
add_library(move_bb8 SHARED
src/move_bb8.cpp
)
ament_target_dependencies(move_bb8 rclcpp std_msgs geometry_msgs)
ament_export_libraries(move_bb8)
# 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!
Asked by samialperen on 2022-03-26 10:48:04 UTC
Answers
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.
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.
Asked by haavarpb on 2022-11-15 05:24:19 UTC
Comments