Why do I have to import Libraries in other packages again?

asked 2021-08-26 19:04:02 -0500

oroshimaru gravatar image

updated 2022-01-22 16:16:14 -0500

Evgeny gravatar image

I am working with ROS and have the following problem:

I have 2 Ros Packages: A and B. And in the package A I am using the prebuilt tensorflow library and everything works fine. The CMakeLists.txt of A has the follwing lines:

find_library(TENSORFLOW_LIB tensorflow HINT /home/tf/lib)
target_link_libraries(A ${PROJECT_NAME}

Now I want to use library A in B, but that does not work. For import I just added the following to the package.xml of B:


With that I can include the headers of A in B but it cannot use the prebuilt binaries, why? For finding the prebuilt binaries it seems like that I need to add the tensorflow_lib to the CMakeLists.txt of project B too. Why do I have to do it twice? Why cant Ros find the tensorflow library by depending on A which uses it?

edit retag flag offensive close merge delete



Stating a dependency in your package manifest does not import it. That information is used for other purposes.

Perhaps #q217475 can clarify some things. After you've read that, please comment here and let us know whether there are still things unclear.

Also related: #q215059.

gvdhoorn gravatar image gvdhoorn  ( 2021-08-27 01:31:34 -0500 )edit

@gvdhoorn Thanks especially for the first link. But I am still struggeling a bit So following example: I have Package A with the Function doA(); and than I caktin build it. To use the function doA(); in my second Package B, I have to make sure that it is an dependency in the package.xml of B. right?

So than in my example: if package A with the function doA(); uses some external library somewhere outside my catkin_ws, than its not enough for package B to only load A as an dependency. So how can I import that external library into my whole catkin_ws, so I do not have to link it in every package that uses Package A.

oroshimaru gravatar image oroshimaru  ( 2021-08-27 13:30:28 -0500 )edit

@gvdhoorn I think I hgave to do something like this; Ros-Wrapping-External_Lib but without having the source code. In my case I onl yhave the prebuilt library

oroshimaru gravatar image oroshimaru  ( 2021-08-27 14:48:18 -0500 )edit

Please do not wrap system dependencies in ROS packages unnecessarily. Tensorflow is already packaged, there should be no need to create any additional wrappers.

Just treat it like any other library/project you'd link with CMake. ROS does not make this special or different.

gvdhoorn gravatar image gvdhoorn  ( 2021-08-27 15:01:35 -0500 )edit
  1. What do you mean with tensorflow is already packaged? http://wiki.ros.org/tensorflow_ros_cpp do you mean this one?
    1. So you mean the way I am doing it right now? In every package that uses PackageA I should change the CMake to link to tensorflow? Wouldnt that be worse? Everybody using the project needs to change the CMakes to his tensorflow path? And you I will get compatibility issues.
oroshimaru gravatar image oroshimaru  ( 2021-08-27 16:13:38 -0500 )edit