0
$\begingroup$

Rosanswers logo

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?


Originally posted by raahlb on ROS Answers with karma: 317 on 2011-10-25

Post score: 0

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

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.


Originally posted by Lorenz with karma: 22731 on 2011-10-25

This answer was ACCEPTED on the original site

Post score: 4


Original comments

Comment by Mac on 2011-10-26:
In every meaningful way, the "build a library and export it" technique is the Right Answer.

Comment by Lorenz on 2011-10-25:
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 :)

Comment by raahlb on 2011-10-25:
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?

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.