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

Revision history [back]

I don't understand why Mylib is required by package B if Package A loaded it without problems

Well, package A doesn't load the shared library Mylib. You specify that whatever you compile in package A should dynamically link to Mylib.so. It is not included in package A in any way.

Now, if you use whatever you compile in package A in package B, you need to tell package B that it needs to link against whatever package A needs to link to as well. You don't have to explicitly do this, you can actually do this as in "hey package B, just link against everything that package A links against", by specifying this correctly in the CMakeLists.txt of package A.

This should explain why it is not working. If you want to know how to make it work, please post a new question and don't forget to include a copy of your CMakeLists.txt, ideally of both packages (and please remove any comments).

I don't understand why Mylib is required by package B if Package A loaded it without problems

Well, package A doesn't load the shared library Mylib. You specify that whatever you compile in package A should dynamically link to Mylib.so. It is not included in package A in any way.

Now, if you use whatever you compile in package A in package B, you need to tell package B that it needs to link against whatever package A needs to link to as well. You don't have to explicitly do this, you can actually do this as in "hey package B, just link against everything that package A links against", by specifying this correctly in the CMakeLists.txt of package A.

This should explain why it is not working. If you want to know how to make it work, please post a new question and don't forget to include a copy of your CMakeLists.txt, ideally of both packages (and please remove any comments).


Update

How can I say

"hey package B, just link against everything that package A links against"?

You've already done that, via find_package(catkin REQUIRED COMPONENTS ... PackageA) and target_link_libraries(some_PackageB_cpp ${catkin_LIBRARIES}). You don't have to specify package_A_launcher there explicitely.

Minor note on the CMakeLists.txt of PackageB: you should have PackageA specified as a CATKIN_DEPENDS, not as a DEPEND in the catkin_package macro. Other than that, this one seems fine. (Though I wonder why you use mpicc in packageA, but not in B. Maybe this also has some influence?)

You need to properly specify PackageA, though. I.e. you have to export to catkin/cmake, which libraries you provide from your PackageA. Otherwise, package B cannot find them.

You do this also in the catkin_package call by adding the LIBRARIES and INCLUDE_DIRS sections. See the catkin docs.

As you provide myLib as a compiled .so, you'll have to work around a few things, though. I'd recommend investigating if there is another way, e.g.

  1. Check, if you can get it from apt (you'll probably have done that, though)
  2. If it is a cmake project, follow the advice from #q246012
  3. If it is something else, you're probably best of by providing a wrapper package for this. Take cob_extern/libntcan as an example on what needs to be done...
  4. you can also do the above within your package, but I'd recommend keeping those two (PackageA and MyLib) separate...