Ask Your Question
0

Create and link ROS library

asked 2015-03-10 07:55:07 -0500

cpiury gravatar image

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 "catkin_init_workspace" 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 catkin_init_workspace 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")
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2015-03-10 12:53:00 -0500

William gravatar image

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.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2015-03-10 07:55:07 -0500

Seen: 438 times

Last updated: Mar 10 '15