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

Linking object files in another package

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

raahlb gravatar image

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

Hi,

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
4

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

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 libfoo.so 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:

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

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

edit flag offensive delete link more

Comments

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 -0600 )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 -0600 )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 -0600 )edit

Question Tools

1 follower

Stats

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

Seen: 1,103 times

Last updated: Oct 25 '11