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

cannot find libroscpp.so if installed node started as root

asked 2018-07-18 15:06:59 -0600

GuillaumeB gravatar image

Hello, I have a node that I am supposed to start as root. Before I was using catkin_make to compile and I was sourcing devel/setup.bash and everything was working perfeclty. But today I tried to use catkin_make install and to source install/setup.bash` and this time my node is crashing. it says:

error while loading shared libraries: libroscpp.so: cannot open shared object file: No such file or directory

I also tried with another node (a dummy one) with the same CmakeLists. And this is really the combination between install and root that seems to be the problem.

my launchfile:

<launch>
  <node name="bb_pigpio_node" pkg="bb_pigpio" type="bb_pigpio_node" launch-prefix="sudo -E">
    <rosparam command="load" file="$(find bb_pigpio)/config/bb_encoder.yaml" />
  </node>
</launch>

My CmakeLists:

cmake_minimum_required(VERSION 2.8.3)
project(bb_pigpio)

add_compile_options(-std=c++11)

find_package(catkin REQUIRED COMPONENTS
  roscpp
  std_msgs
)

###################################
## catkin specific configuration ##
###################################
catkin_package(
  INCLUDE_DIRS include
  LIBRARIES bb_pigpio
  CATKIN_DEPENDS roscpp std_msgs
)

###########
## Build ##
###########

## Specify additional locations of header files
include_directories(
  include
  ${catkin_INCLUDE_DIRS}
)

## Declare a C++ executable
add_executable(${PROJECT_NAME}_node src/encoder_node.cpp
                                    src/encoder.cpp)

add_dependencies(${PROJECT_NAME}_node ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})

target_link_libraries(${PROJECT_NAME}_node
  ${catkin_LIBRARIES}
  pigpio
)
#############
## Install ##
#############

install(TARGETS ${PROJECT_NAME}_node
   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 "*.hpp"
 )

 install(DIRECTORY launch/
   DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}/launch
 )

 install(DIRECTORY config/
   DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}/config
 )

Thanks for your help

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2018-07-19 13:04:55 -0600

GuillaumeB gravatar image

So, I figure out how to make this work.

The reason why it wasn't working was: The option -E (preserve environment) of Sudo present the environment except for variable like PATH, LD_LIBRARY_PATH etc are not preserved.

In my case, LD_LIBRARY_PATH was needed (to find libroscpp.so). So I fixed it by explicitely sending this variable to the sudo environement:

  <node name="bb_pigpio_node" pkg="bb_pigpio" type="bb_pigpio_node" launch-prefix="sudo -E LD_LIBRARY_PATH=$(optenv LD_LIBRARY_PATH)">
    <rosparam command="load" file="$(find bb_pigpio)/config/bb_encoder.yaml" />
  </node>

There is still a question. Why it was working without this using the devel/build directory and not the install one.

edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2018-07-18 15:06:59 -0600

Seen: 979 times

Last updated: Jul 19 '18