2

I've had this issue multiple times with different libraries. The colcon build runs fine but at launch ros2 complaints that the shared objects were not found. Is there a better way to add the path other than setting $LD_LIBRARY_PATH env variable?

I link the external libraries (eg: libtorch) in cmake as

target_link_libraries(some_proj
  ${TORCH_LIBRARIES}
)

install(TARGETS some_proj
  EXPORT export_${PROJECT_NAME}
  ARCHIVE DESTINATION lib
  LIBRARY DESTINATION lib
  RUNTIME DESTINATION lib/${PROJECT_NAME}
)

install(DIRECTORY
  launch
  DESTINATION share/${PROJECT_NAME}/
)

ament_package()
mro47
  • 83
  • 5

1 Answers1

2

Setting RPATH as @Jesper said worked. Also see this answer

Apparantly the RPATH is stripped when the package is installed. The following setting in cmake will keep the RPATH

Set this in the cmake before building any targets (executables / libs)

set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)

Or set it for a specific target

set_target_properties(${some_target} PROPERTIES INSTALL_RPATH_USE_LINK_PATH TRUE)
mro47
  • 83
  • 5