linking a library exported by another ROS package [closed]

asked 2013-08-05 00:06:59 -0600

kid-a gravatar image

updated 2013-08-05 03:28:39 -0600

Hi there,

I have two ROS packages, ros_mathlib and spa_depth_model.
Both of them are written in C++ and export shared objects (.so).
The latter depends on the former, that is spa_depth_model makes use of classes implemented by ros_mathlib.

Following the documentation, I added the following lines to the manifest file of ros_mathlib:

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

while the manifest of spa_depth_model simply states its dependency on ros_mathlib:

...
<depend package="ros_mathlib"/> 
...

Now, building ros_depth_model works fine (a shared object is produced, so ros_mathlib is not actually linked).
However, building its tests results in a linking error:

$ make tests
...
Linking CXX executable ../bin/tests
CMakeFiles/tests.dir/test/tests.o: In function `GaussianMixtureModels_depthInverseModel2W_Test::TestBody()':
/home/loris/spa_depth_model/test/tests.cc:186: undefined reference to `Vector::undef'

If I explicitly specify the dependence of the test on ros_mathlib in the CMakelists.txt file, the error goes away:

rosbuild_add_gtest(tests test/tests.cc)
target_link_libraries(tests ${PROJECT_NAME} ros_mathlib)

However, editing CMakelists.txt seems not to be the recommended way to link against libraries exported by other ROS packages.

I believe there's something wrong in my current understanding of how to link against other packages in ROS, and I'd be glad to hear from you on this.

edit retag flag offensive reopen merge delete

Closed for the following reason question is not relevant or outdated by tfoote
close date 2016-04-27 02:00:13.468993