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

Error with shared objects when building from source

asked 2021-04-05 13:41:42 -0500

rezenders gravatar image

Hello,

I am trying to build ROS + a few packages that I created from source in a rasp3 due to this issue: https://answers.ros.org/question/3510...

I am able to compile everything. I had to explicitly describe what I wanted to install in the CMakeLists in order to be able to run everything when sourcing installed_isolated/setup.bash.

Now I can find everything but when I run a node called obstacle_detector_single_scan it is not finding the required shared objects, I am getting this error (I had to run with debug flag to get this error msg):

/home/gus/ros_catkin_ws/install_isolated/lib/robot_safety_collision_avoidance/obstacle_detector_single_scan: error while loading shared libraries: libobstacle_detector_core.so: cannot open shared object file: No such file or directory

The CMakeList I have is:

cmake_minimum_required(VERSION 3.5)
project(robot_safety_collision_avoidance)

## Use C++14
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)


## Find catkin macros and libraries
## if COMPONENTS list like find_package(catkin REQUIRED COMPONENTS xyz)
## is used, also find other catkin packages
find_package(catkin REQUIRED COMPONENTS
  geometry_msgs
  roscpp
  rospy
  std_msgs
  shape_msgs
  sensor_msgs
  std_srvs
  roslint
)

## Find system libraries
find_package(Boost REQUIRED)

###################################
## catkin specific configuration ##
###################################
catkin_package(
  INCLUDE_DIRS
    include
  LIBRARIES
    obstacle_detector_core
  CATKIN_DEPENDS
    roscpp
    sensor_msgs
    shape_msgs
  DEPENDS
)

roslint_cpp()

###########
## Build ##
###########
include_directories(
  include
  ${catkin_INCLUDE_DIRS}
  # Set because Boost is an internal dependency, not transitive.
  #${Boost_INCLUDE_DIRS}
)

## Declare a cpp library
add_library(obstacle_detector_core
   src/ObstacleAlgorithm.cpp
)
target_compile_features(obstacle_detector_core INTERFACE cxx_std_11)

## Declare cpp executables
add_executable(obstacle_detector
  src/obstacle_detector_node.cpp
  src/ObstacleDetector.cpp
)
target_compile_features(obstacle_detector INTERFACE cxx_std_11)



add_executable(obstacle_detector_single_scan
  src/obstacle_detector_single_scan_node.cpp
  src/ObstacleDetectorSingleScan.cpp
)
target_compile_features(obstacle_detector_single_scan INTERFACE cxx_std_11)


add_executable(collision_avoidance
  src/collision_avoidance_node.cpp
  src/CollisionAvoidance.cpp
)
target_compile_features(collision_avoidance INTERFACE cxx_std_11)

## Add dependencies to exported targets, like ROS msgs or srvs
add_dependencies(obstacle_detector_core
  ${catkin_EXPORTED_TARGETS}
)

add_dependencies(obstacle_detector
  ${catkin_EXPORTED_TARGETS}
)

## Specify libraries to link executable targets against
target_link_libraries(obstacle_detector_core
  ${catkin_LIBRARIES}
)

target_link_libraries(obstacle_detector
  obstacle_detector_core
  ${catkin_LIBRARIES}
)

target_link_libraries(obstacle_detector_single_scan
  obstacle_detector_core
  ${catkin_LIBRARIES}
)

target_link_libraries(collision_avoidance
  ${catkin_LIBRARIES}
)


##########################
## Static code analysis ##
##########################
roslint_cpp()

install(DIRECTORY
    launch
    config
    DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}
)

install(TARGETS
    obstacle_detector
    obstacle_detector_single_scan
    collision_avoidance
    ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
    LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
    RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
)

install(DIRECTORY
    include/${PROJECT_NAME}/
    DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION}
    FILES_MATCHING PATTERN "*.h" PATTERN "*.hpp"  PATTERN ".svn"
    EXCLUDE PATTERN ".git" EXCLUDE
)

I guess I have to add something to CMakeList in order to install the shared objects? How can I do this?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2021-04-05 14:29:24 -0500

rezenders gravatar image

Fixed by adding obstacle_detector_core to the install target, and adding the libraries names in catkin_package LIBRARIES field.

catkin_package(
  INCLUDE_DIRS
    include
  LIBRARIES
    obstacle_detector
    obstacle_detector_core
    obstacle_detector_single_scan
    collision_avoidance
  CATKIN_DEPENDS
    roscpp
    sensor_msgs
    shape_msgs
  DEPENDS
)

install(TARGETS
    obstacle_detector
    obstacle_detector_core
    obstacle_detector_single_scan
    collision_avoidance
    ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
    LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
    RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
)
edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2021-04-05 13:41:42 -0500

Seen: 98 times

Last updated: Apr 05 '21