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

how to use so file in ros

asked 2014-08-13 02:13:11 -0600

general_zclu gravatar image

Hello, I want to use a .so file in the ros. And I add the .h and .so file in the /usr/include/ What else should I do? Thanks very much!

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
4

answered 2014-08-13 02:52:00 -0600

BennyRe gravatar image

updated 2014-08-14 01:12:52 -0600

Putting files by hand into /usr/include isn't a nice solution to your problem.

If this header file and library is contained in a debian package then the perfect solution is to simply depend on that package.

If this isn't the case but you have the source code of the library you can create an own package for it.

These two steps are recommended in the ROS Wiki Using thrid party libs.

If you haven't got access to the code you out the header and library inside your package and link the library withtarget_link_libraries

Edit:

I wouldn't put everything in src. I would put the headers in include and the shared objects in lib. In your CMakeLists.txt there's a boilerplate target_link_libraries. Add there the location of the shared object.

For example:

target_link_libraries(your_node ${catkin_LIBRARIES} ${PROJECT_SOURCE_DIR}/lib/libxyz.so)
edit flag offensive delete link more

Comments

Thanks very much! I haven't got access to the code. I have put the files .h and .so in ~/catin_ws/src/beginner_tutorials/src and I don't know how to write the CMakeLists, would you please tell me the details on how to write "target_link_library" and other place need to write. Thanks!

general_zclu gravatar image general_zclu  ( 2014-08-13 20:52:25 -0600 )edit

See my edit

BennyRe gravatar image BennyRe  ( 2014-08-14 01:12:59 -0600 )edit

Thanks very much! And I wonder how to use the function in .so. When I just include ".h", and use the function in the .so, catkin_make say cannot find the function. If I need #include "dlfcn.h" and use dlopen and dlsym to get the function? Thanks a lot!

general_zclu gravatar image general_zclu  ( 2014-08-14 08:20:31 -0600 )edit

Hi..I a have a doubt here...

Declare a C++ library

add_library(iarm_exact_dynamics

src/${PROJECT_NAME}/iarm_exact_dynamics.cpp

)

whats is this for?

khairulizwan gravatar image khairulizwan  ( 2015-11-23 05:54:52 -0600 )edit

@khairulizwan This compiles a library called iarm_exact_dynamics from the given source file.

BennyRe gravatar image BennyRe  ( 2015-11-23 06:59:44 -0600 )edit

Still in doubt/unclear about this. I am trying the create the iARM package. iARM manufacturer provided the .h file, .lib file and also .so file. Are this procedure correct: 1. copy the .h file --> include (mkdir -p include?) 2. copy the .so file --> lib (mkdir -p lib?) 3. edit the CMakelist.txt

khairulizwan gravatar image khairulizwan  ( 2015-12-16 00:54:40 -0600 )edit

How about .lib file?

khairulizwan gravatar image khairulizwan  ( 2015-12-16 01:50:19 -0600 )edit

@khairulizwan yes, I'd say that's the correct approach. I never worked with .lib files but it should work the same way.

BennyRe gravatar image BennyRe  ( 2015-12-17 02:03:06 -0600 )edit

Question Tools

Stats

Asked: 2014-08-13 02:13:11 -0600

Seen: 4,217 times

Last updated: Aug 14 '14