Shared libraries placed at different location on compilation than required at runtime

asked 2021-08-26 07:46:57 -0600

Martiasv gravatar image

updated 2021-08-27 14:28:16 -0600

Mike Scheutzow gravatar image

Hi,

I am trying to run a ros-node that I made, but I am getting this error:

/home/martiasv/birdview_ws/install/rtls/lib/rtls/Virtual_RTLS_Sensor: error while loading shared libraries: libVirtual_RTLS_Sensor_node.so: cannot open shared object file: No such file or directory

The file it is complaining about has been placed in this directory by Colcon:

/home/birdview_ws/build/rtls/libVirtual_RTLS_Sensor_node.so

When I try to run other ROS-nodes, the same thing happens.

Why are these files placed in a different directory when I run colcon build than what ROS looks for when I run ros2 run? How can I get Colcon to place these files in the correct directory so that I can run my ROS nodes?

I am running: Ubuntu 20.04 ROS2 Galactic

This is my CMakeLists.txt for reference:

cmake_minimum_required(VERSION 3.5)
project(rtls)

# Default to C++14
if(NOT CMAKE_CXX_STANDARD)
  set(CMAKE_CXX_STANDARD 14)
endif()

if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
  add_compile_options(-Wall -Wextra -Wpedantic)
endif()

# find dependencies
find_package(ament_cmake REQUIRED)
find_package(rclcpp REQUIRED)
find_package(std_msgs REQUIRED)
find_package(geometry_msgs REQUIRED)
find_package(Eigen3 REQUIRED)
find_package(px4_msgs REQUIRED)

set(dependencies
  rclcpp
  std_msgs
  geometry_msgs
  Eigen3
  px4_msgs
)

install(DIRECTORY include/
    DESTINATION include
)


include_directories(include ${EIGEN3_INCLUDE_DIRS})

add_library(Position_attitude_SF_library SHARED src/Position_attitude_SF_library.cpp)
ament_target_dependencies(Position_attitude_SF_library ${dependencies})

add_library(rtls_sensor_tag SHARED src/rtls_sensor_tag.cpp)
ament_target_dependencies(rtls_sensor_tag ${dependencies})

add_library(rtls_sensor_anchor SHARED src/rtls_sensor_anchor.cpp)
ament_target_dependencies(rtls_sensor_anchor ${dependencies})

add_library(Position_attitude_SF_node SHARED src/Position_attitude_SF_node.cpp)
ament_target_dependencies(Position_attitude_SF_node ${dependencies})

add_library(Virtual_RTLS_Sensor_node SHARED src/Virtual_RTLS_Sensor_node.cpp)
ament_target_dependencies(Virtual_RTLS_Sensor_node ${dependencies})

add_executable(Position_attitude_SF src/Position_attitude_SF.cpp)
target_link_libraries(Position_attitude_SF Position_attitude_SF_node Position_attitude_SF_library rtls_sensor_tag rtls_sensor_anchor Virtual_RTLS_Sensor_node)
ament_target_dependencies(Position_attitude_SF ${dependencies})

add_executable(Virtual_RTLS_Sensor src/Virtual_RTLS_Sensor.cpp)
target_link_libraries(Virtual_RTLS_Sensor Position_attitude_SF_node Position_attitude_SF_library rtls_sensor_tag rtls_sensor_anchor Virtual_RTLS_Sensor_node)
ament_target_dependencies(Virtual_RTLS_Sensor ${dependencies})

install(TARGETS Position_attitude_SF Virtual_RTLS_Sensor
    ARCHIVE DESTINATION lib
    LIBRARY DESTINATION lib
    RUNTIME DESTINATION bin
    INCLUDES DESTINATION include
)

ament_export_include_directories(include)
ament_export_dependencies(${dependencies})

ament_package()
edit retag flag offensive close merge delete

Comments

Just a quick comment (and not a solution at all):

How can I get Colcon to place [..]

Colcon does not do anything with your files, nor libaries.

It's all CMake.

gvdhoorn gravatar image gvdhoorn  ( 2021-08-26 10:57:40 -0600 )edit

Have you tried cleaning the workspace, then rebuilding from a clean slate? See #q330109

Mike Scheutzow gravatar image Mike Scheutzow  ( 2021-08-26 14:46:16 -0600 )edit

Yes, I have tried a complete cleaning of the workspace, and done a full re-install of ROS and all dependencies.

Martiasv gravatar image Martiasv  ( 2021-08-27 06:35:01 -0600 )edit

Please show us the output of these 2 commands:

ls /home/martiasv/birdview_ws/install/rtls/lib
echo $LD_LIBRARY_PATH
Mike Scheutzow gravatar image Mike Scheutzow  ( 2021-08-27 13:58:23 -0600 )edit

Also, take a look at the answer to this question #q350976 about shared_libs and export directives.

Mike Scheutzow gravatar image Mike Scheutzow  ( 2021-08-27 14:17:12 -0600 )edit