Robotics StackExchange | Archived questions

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

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}
        ${TENSORFLOW_LIB})

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:

<depend>A</depend>

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?

Asked by oroshimaru on 2021-08-26 19:04:02 UTC

Comments

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.

Asked by gvdhoorn on 2021-08-27 01:31:34 UTC

@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.

Asked by oroshimaru on 2021-08-27 13:30:28 UTC

@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

Asked by oroshimaru on 2021-08-27 14:48:18 UTC

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.

Asked by gvdhoorn on 2021-08-27 15:01:35 UTC

  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.

Asked by oroshimaru on 2021-08-27 16:13:38 UTC

Answers