I am trying to catkin build this ROS package https://github.com/toddhester/rl-texplore-ros-pkg but it fails to build 'rl_experiment' with the following error:
/usr/bin/ld: cannot find -lagentlib
/usr/bin/ld: cannot find -lenvlib
collect2: error: ld returned 1 exit status
I am using ROS Kinetic. The shared libraries does exist in the folders /texplore/devel/.private/rl_env/lib/ and /texplore/devel/.private/rl_agent/lib/ with symlinks at /texplore/devel/lib/
I tried the following:
(1) export /texplore/devel/lib/ to LD_LIBRARY_PATH
(2) adding symlinks to the libraries in /texplore/src/rl_experiment/src
(3) adding the library paths to target_link_libraries
target_link_libraries(experiment agentlib envlib ${catkin_LIBRARIES}
"/media/usr/texplore/devel/lib/libagentlib.so"
"/media/usr/texplore/devel/lib/libenvlib.so")
(4) set the search path for linker
SET(CMAKE_EXE_LINKER_FLAGS
"${CMAKE_EXE_LINKER_FLAGS} -Wl,-rpath -Wl,/media/usr/texplore/devel/lib/")
It didn't work. Lastly, I added the symlinks to /usr/local/lib and it worked. But I do not want the symlinks in this folder.
So the linker is simply not searching the build tree. My question is, why did catkin not add the linker path in catkin_LIBRARIES? I have built ROS packages before but can't wrap my head around why this particular package is not working.
I ran into the same issue. I made the following changes based on this post on ROS Answers and the below comment in the generic CMakeLists.txt file for the catkin_packages macro:
## LIBRARIES: libraries you create in this project that dependent projects also need
I did a few things to fix this...
LIBRARIES agentlib
to the catkin_packages
macro in the rl_agent/CMakeLists.txt
file. This makes the agentlib
library available later to rl_experiment
.LIBRARIES envlib
to the catkin_packages
macro in the rl_env/CMakeLists.txt
file. This makes the envlib
library available later to rl_experiment
.agentlib
and envlib
from the target_link_libraries
macro in the rl_experiment/CMakeLists.txt
file. These are not necessary.rl_agent
and rl_env
packages are listed in the find_package
macro of the rl_experiment/CMakeLists.txt
....then everything successfully compiled.
Adding snippets for further clarification...
...
## Declare a cpp library
# add_library(rgbd_tools
# src/${PROJECT_NAME}/
# )
add_library(agentlib
src/Agent/DiscretizationAgent.cc
src/Agent/QLearner.cc
...
src/newmat/newmatrm.cc
src/newmat/newmat9.cc
)
## Declare a cpp executable
# add_executable(rgbd_tools_node src/rgbd_tools_node.cpp)
...
...
###################################
## catkin specific configuration ##
###################################
...
catkin_package(
INCLUDE_DIRS include
LIBRARIES envlib
# CATKIN_DEPENDS roscpp rospy std_msgs
CATKIN_DEPENDS message_runtime
# DEPENDS system_lib
)
...
...
## 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
roscpp
std_msgs
rl_common
rl_env
rl_agent
)
## System dependencies are found with CMake's conventions
# find_package(Boost REQUIRED COMPONENTS system)
...
## Declare a cpp executable
# add_executable(rgbd_tools_node src/rgbd_tools_node.cpp)
add_executable(experiment src/rl.cc)
# target_link_libraries(experiment agentlib envlib ${catkin_LIBRARIES})
target_link_libraries(experiment ${catkin_LIBRARIES})
#add_executable(image_converter src/image_converter.cpp)
...