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

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 libtest.so. 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)
set(EXTRALIB_BIN ${PROJECT_SOURCE_DIR}/lib/libtest.so)
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

Comments

1

FYI: found a solution: target_link_libraries( test_service_server ${catkin_LIBRARIES} ${PROJECT_SOURCE_DIR}/lib/libtest.so.1) 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
3

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

Comments

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

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

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

Comments

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

Stats

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

Seen: 1,451 times

Last updated: Jul 12 '21