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 :-)