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

adding shared objects to catkin package

asked 2015-05-08 07:41:23 -0500

Reiner gravatar image

updated 2015-05-11 04:37:45 -0500

Hi, i'm writing a node that has to call some functions from a .so library. The node called test_service_server has to use functions from This lib is NOT a catkin lib, it was created outside of ROS entirely.

inside my CMakeLists.txt i have the following:

include_directories( ${catkin_INCLUDE_DIRS} lib)
add_executable(test_service_server src/test_service_server.cpp)
target_link_libraries( test_service_server ${catkin_LIBRARIES} ${EXTRALIB_BIN})

I still get the error: no rule to make target.

Can someone give me a few tipps about linking shared objects to catkin packages?

EDIT: Just to explain my problem better: I have a shared object lib with ca 200 functions my node needs. ( in the /lib folder of the package) These functions are described in header files (ca. 10, in the /include folder of the package).

I can't get the source of this library to try and build it as a catkin lib. how do i properly link my .so in CMakeLists.txt?

edit retag flag offensive close merge delete



FYI: found a solution: target_link_libraries( test_service_server ${catkin_LIBRARIES} ${PROJECT_SOURCE_DIR}/lib/ this use of target link libraries works perfectly, in case someone stumbles upon the question.

Reiner gravatar image Reiner  ( 2015-06-02 03:22:13 -0500 )edit

2 Answers

Sort by ยป oldest newest most voted

answered 2015-05-11 04:53:06 -0500

gvdhoorn gravatar image

Even though @Wolf's answer should work for you, I'll add some references to earlier questions that asked the same thing:

The accepted answer to the second question also has some links to pkgs that do the same thing.

edit flag offensive delete link more


thanks, those two links were a huge help for me:)

Reiner gravatar image Reiner  ( 2015-05-11 08:33:02 -0500 )edit

answered 2015-05-08 15:57:26 -0500

Wolf gravatar image

updated 2021-07-12 16:05:49 -0500

lucasw gravatar image

I assume its a precompiled lib you have copied to your project folders /lib directory. If so you need to

link_directories(  ${PROJECT_SOURCE_DIR}/lib )

target_link_libraries( test_service_server ${catkin_LIBRARIES} test )

Note: link_directories specifies the path for your libs target_link_libraries takes the library names without lib prefix and .so postfix.

Also note that this is only valid if its a somehow outside catkin created lib. If catkin creates the lib it won't put them in the lib folder of your project but into the devel/lib folder of your workspace so the workaround is different then...

edit flag offensive delete link more


Yes, it is a precompiled lib, made outside of catkin. i tried your method with link_directories, unfortunately with the result: /usr/bin/ld: cannot find -ltest

Reiner gravatar image Reiner  ( 2015-05-11 04:19:12 -0500 )edit

sorry for the late comment, i've got it running, though i still needed both the lib prefix and the so postfix

Reiner gravatar image Reiner  ( 2015-06-02 03:20:24 -0500 )edit

Question Tools


Asked: 2015-05-08 07:41:23 -0500

Seen: 1,462 times

Last updated: Jul 12 '21