Create and link ROS library
Hi, I have implemented a ROS library and I have "mylibrary.so" file. Now I want to use this library in another external project and I don't know how to do this. I have in my new project a CMakeLists.txt and in it I link my library in the following way:
INCLUDE_DIRECTORIES("path_to_include_directory")
ADD_EXECUTABLE(foo main.cpp)
TARGET_LINK_LIBRARIES(foo "path_to_my_library.so")
But this doesn't work and I get undefined reference to the implemented functions. My new project is not created with "catkininitworkspace" since it's not a 100% ROS project, so... If I want to use my ros library, my new project (that is not a 100% ROS project, only uses my ros library for 2 little tasks) must be created with the catkininitworkspace and create in it a node that uses this library? or are there any way to use my ros library into my new project without the catkin_workspace / node architecture?, I mean, creating something like:
-Project
|-build
|-src
|-CMakeLists.txt
|-main.cpp
And inside CMakeLists.txt something like:
TARGET_LINK_LIBRARIES(executable "path_to_my_library.so")
Asked by cpiury on 2015-03-10 07:55:07 UTC
Answers
Your ROS package you are trying to use in your non-ROS CMake project generates CMake files. You can just do:
find_package(my_ROS_package REQUIRED)
include_directories(${my_ROS_package_INCLUDE_DIRS})
...
target_link_libraries(executable ${my_ROS_package_LIBRARIES})
in the non-ROS CMake project you have. Just make sure to source the setup.bash
file generated from building your ROS package's workspace, otherwise it might not be on the CMAKE_PREFIX_PATH
.
Asked by William on 2015-03-10 12:53:00 UTC
Comments