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

Determine path to executable

asked 2015-05-12 03:03:16 -0500

SR gravatar image

I want to determine the absolute path to a binary I built. With rospack find I can get the path to the package itself. However, finding the path to the executable is much harder: In the devel workspace it usually is in <workspace>/devel/lib/<project> but when the package is deployed and installed to ${CATKIN_PACKAGE_SHARE_DESTINATION} it is located directly in <install prefix>/<project>/.

In both cases I can run that binary with rosrun <package> <binary> but I did not find a way to get the corresponding path. Is there a portable way to get the absolute path to a binary?

edit retag flag offensive close merge delete


I can think of a "portable" way for this.. Why would you want to to this? Maybe there is another workaround for your problem!?

Wolf gravatar image Wolf  ( 2015-05-12 03:18:18 -0500 )edit

Portable here means "working for both development workspaces as well as installed packages." I do not loke workarounds where I have to add if/else clauses at every place where I want to get the absolute path to my binary.

SR gravatar image SR  ( 2015-05-12 05:23:51 -0500 )edit

Still, want do you intent to do with the path? Usually you do not need to know the path as rosrun and roslaunch do locate the file for you!

Wolf gravatar image Wolf  ( 2015-05-12 05:26:00 -0500 )edit

I want to run the binary by using the absolute path. I have to run the binary as quickly as possible as we measure the elapsed time of certains tasks. For that reason I want to avoid rosrun as it traverses the whole filesystem (I assume via rospack find, which can be relatively slow).

SR gravatar image SR  ( 2015-05-12 16:36:09 -0500 )edit

catkin_find uses a similar logic as tools like rospack. It also needs to crawl the filesystem.

Dirk Thomas gravatar image Dirk Thomas  ( 2015-05-13 03:50:25 -0500 )edit

Ok, thanks. Yes, catkin_find works for me, but only if I sourced all devel workspaces, while rosrun apparently finds its packages via ROS_PACKAGE_PATH.

SR gravatar image SR  ( 2015-05-13 08:21:57 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2015-05-12 07:17:06 -0500

Dirk Thomas gravatar image

By default the location of the executable should be the same:

  • <devel_space>/lib/<pkg_name>/<executable_name>
  • <install_space>/lib/<pkg_name>/<executable_name>

If it is not in your case may be it helps to post your CMake file to provide more information.

Anyway you should be able to find your executable by invoking: catkin_find <pkg_name> <executable_name>

You can narrow down the search with various options (see catkin_find --help).

edit flag offensive delete link more


Thank you for your answer. I will have a look and try catkin_find. Is it only available in build environments or also for production/installed packages? I will also re-check why our package layout of the installed files is different to that of the devel_space.

SR gravatar image SR  ( 2015-05-12 16:34:12 -0500 )edit

The executable is provided as part of the catkin package: see which catkin_find and dpkg -S /opt/ros/indigo/bin/catkin_find.

Dirk Thomas gravatar image Dirk Thomas  ( 2015-05-13 03:50:23 -0500 )edit

Thank you!

SR gravatar image SR  ( 2015-05-13 08:22:33 -0500 )edit

It works for me but only if the catkin workspace/devel/setup.bash was properly sourced. rosrun works all the time because it only relies on the path being in ROS_PACKAGE_PATH. Thus the behaviour of catkin_find is not quite identical to rosrun.

SR gravatar image SR  ( 2015-05-18 02:43:55 -0500 )edit

Question Tools



Asked: 2015-05-12 03:03:16 -0500

Seen: 10,499 times

Last updated: May 12 '15