Ask Your Question
0

Questions Regarding ROS Package Dependencies

asked 2021-08-16 21:01:29 -0500

charmflex gravatar image

updated 2021-08-16 21:02:47 -0500

Hi. I am quite new to ROS and its ecosystem so I have some questions regarding the package dependencies that really confusing me.

For example, I want to build my own package and run my own code. I imported a lot of other packages/libraries such as opencv, geometry_msg, sensor_msgs, numpy, matplotlib, etc. Is it necessary for me to list all the libraries/dependencies that I used in package.xml and CMakeList.txt?

I run the code without listing the other dependencies except roscpp, std_msgs, rospy, and it does run. Why is it so?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2021-08-17 00:40:30 -0500

mgruhler gravatar image

updated 2021-08-17 02:47:16 -0500

It depends a bit which language you are using (you say "imported" and numpy, so I guess python).

  • If you are using python, you can sure run basically any python script/executable without having to list them, given that the packages are already properly installed.
  • If you are using C++, you need to put the dependencies you require to build your package into the appropriate cmake calls (specifically, find_package, [target_]include_directories, target_link_libraries, etc.) in the CMakeLists.txt. Again, this is given that they are already installed. You might be able to not list some, if they are transitive dependencies (i.e. dependencies of your dependencies and those dependencies export the required variables such that you can, basically, "reuse" them).

For the package.xml: This file is part of the ROS "dependency management system" rosdep. If you add your dependencies there, it is clear what you package requires to build and/or run. This file is read during the calls to rosdep install <some_package> and automatically installs the required packages. So this can be seen as a prerequisite to building/running. Also, once you start distributing your package, this is the minimum what a user expects. If you distribute C++ packages, you have to check additional calls in the CMakeLists.txt as well (especially the catkin_package call and the various install commands).

EDIT

do you mean that even if I do not list any dependencies (rospy, roscpp, std_msgs, etc), it will still run normally, right?

When using python, for the most part yes.

Even if I don't distribute packages, I must list all the dependencies in cmakelist.txt if I am using C++?

Yes

Why are there differences between python and C++, where I don't need to list dependencies if I write in python, the other way round if in C++?

I think this question would take us way beyond what can be answered simply here. But to give a few pointers

  • Python is an interpreted language and as such does not need to be "compiled". There is no compile step.
  • Once a python module/package is installed and is on the PYTHONPATH you can use (i.e. import) it and you application will run. The path is set up when you source your ROS workspace.
  • note that this might change when you want to depend on one of your own packages... ROS helps a lot and does some things under the hood. But there is no magic involved.
  • C++ needs to be compiled, and the compiler needs to know how.
  • You need to tell the C++ compiler where to find headers, libs, etc. because there is no "standard location"
  • You do this (at least when using ROS) with the CMake Buildsystem.

I suggest to read up on CMake a bit, or check the relevant wiki pages in ROS.

Closing Comments I suggest to always properly specify your dependencies. This will help you, future-you and others a lot. Also, it is considered good style :-)

edit flag offensive delete link more

Comments

Yes, I use python. Since I don't distribute packages, instead I just use ROS for self-purpose, do you mean that even if I do not list any dependencies (rospy, roscpp, std_msgs, etc), it will still run normally, right?

Even if I don't distribute packages, I must list all the dependencies in cmakelist.txt if I am using C++? Why are there differences between python and C++, where I don't need to list dependencies if I write in python, the other way round if in C++?

charmflex gravatar image charmflex  ( 2021-08-17 01:13:56 -0500 )edit

see edit above.

mgruhler gravatar image mgruhler  ( 2021-08-17 02:45:46 -0500 )edit
1

This reads a bit like #q217475.

gvdhoorn gravatar image gvdhoorn  ( 2021-08-17 02:53:00 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2021-08-16 21:01:29 -0500

Seen: 125 times

Last updated: Aug 17 '21