CMake Install Targets
I have a project with one executable and multiple libraries. When installing this package, I get a shared libraries error:
/opt/ros/hydro/lib/handle_detector/localization: error while loading shared libraries: libaffordances_lib.so: cannot open shared object file: No such file or directory.
Now, I have added the libraries as install targets to the CMakeLists.txt, but I'm still wondering whether it is correct.
cmake_minimum_required(VERSION 2.8.3)
project(handle_detector)
find_package(catkin REQUIRED COMPONENTS
eigen_conversions
geometry_msgs
message_generation
roscpp
pcl_ros
pcl_conversions
std_msgs
tf
tf_conversions
visualization_msgs)
find_package(LAPACK REQUIRED)
find_package(Eigen REQUIRED)
include_directories(${Eigen_INCLUDE_DIRS})
set(CMAKE_CXX_FLAGS "-DNDEBUG -O3 -fopenmp")
add_message_files(
FILES
CylinderMsg.msg
CylinderArrayMsg.msg
HandleListMsg.msg
)
generate_messages(DEPENDENCIES geometry_msgs)
catkin_package(
LIBRARIES
${PROJECT_NAME}
CATKIN_DEPENDS
eigen_conversions
geometry_msgs
message_generation
roscpp
pcl_ros
pcl_conversions
std_msgs
tf
tf_conversions
visualization_msgs
DEPENDS
Eigen
LAPACK)
include_directories(${catkin_INCLUDE_DIRS})
add_executable(localization src/localization.cpp)
add_library(affordances_lib src/affordances.cpp)
add_library(visualizer_lib src/visualizer.cpp)
add_library(messages_lib src/messages.cpp)
add_library(cylindrical_shell_lib src/cylindrical_shell.cpp)
add_dependencies(messages_lib ${PROJECT_NAME}_gencpp)
target_link_libraries(localization ${catkin_LIBRARIES})
target_link_libraries(localization affordances_lib)
target_link_libraries(localization visualizer_lib)
target_link_libraries(localization messages_lib)
target_link_libraries(affordances_lib ${catkin_LIBRARIES})
target_link_libraries(affordances_lib cylindrical_shell_lib)
target_link_libraries(affordances_lib lapack)
target_link_libraries(messages_lib ${catkin_LIBRARIES})
install(TARGETS localization affordances_lib visualizer_lib messages_lib cylindrical_shell_lib
ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
)
install(DIRECTORY launch/
DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}/launch)
That looks reasonable. I would start troubleshooting by trying to confirm that all of your libraries are actually getting installed into the lib directory.
I'm wondering whether the `LIBRARIES ${PROJECT_NAME}` is actually correct in your catkin_package(..) call. You do specify a number of library targets, but none of them have the name of your project (ie: `handle_detector`).
So, e.g., the line add_library(affordances_lib src/affordances.cpp) would become add_library(${PROJECT_NAME}affordances src/affordances.cpp), right? And I would have to change all other places where this library is used in the CMakeLists.txt?
For now, I would just remove the `LIBRARIES ${PROJECT_NAME}` from your catkin_package call.
@atp: I'd follow @ahendrix advice: just remove that line for now and try to get your package working first.
I did remove it yesterday. Thanks for the advice!
If this is resolved for you, can you post a answer to that effect? Thanks!