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

Linking object files in another package

asked 2011-10-25 19:43:33 -0500

raahlb gravatar image

updated 2011-10-25 19:44:31 -0500


Is there some way to directly link object files (.o) from another package, or is the only possible way to do it to change the build configuration of the second package so it creates a library file?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2011-10-25 20:02:50 -0500

Lorenz gravatar image

Normally, I would say you should create a library. Just use the CMake macro

rosbuild_add_library(foo src/foo.cpp src/bar.cpp)

In this example, a library named is created from files foo.cpp and bar.cpp.

To use your library from other packages, you also need to update your manifest file. In our example, you need to add this:

  <cpp cflags="-I${prefix}/include" lflags="-Wl,-rpath,${prefix}/lib -L${prefix}/lib -lfoo"/>

To use your library in another package you can now just depend on your package.

edit flag offensive delete link more


Yes, I've done that. I was just wondering if there was some easier way to do it. Not that it it is that complex, but still, I was hoping to just link towards the .o files. As far as you know, there is no way to do that?
raahlb gravatar image raahlb  ( 2011-10-25 20:31:38 -0500 )edit
There might be a pretty hacky way by using the rosbuild cmake macros to find the path to a package and some cmake magic to find all object files in that package. But I wouldn't feel good with that solution :)
Lorenz gravatar image Lorenz  ( 2011-10-25 20:34:44 -0500 )edit
In every meaningful way, the "build a library and export it" technique is the Right Answer.
Mac gravatar image Mac  ( 2011-10-26 10:12:33 -0500 )edit

Question Tools

1 follower


Asked: 2011-10-25 19:43:33 -0500

Seen: 1,064 times

Last updated: Oct 25 '11