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

How to chain three catkin workspaces?

asked 2016-07-03 13:29:52 -0600

Cerin gravatar image

updated 2016-07-03 13:33:00 -0600

How do you chain three catkin workspaces so that their setup.bash files don't conflict?

I tried following the instructions in the wiki, but they're a bit confusing and don't seem to be correct.

My workspaces are:

  1. the base Kinetic workspace installed into the standard /opt/ros/kinetic location
  2. a workspace containing third-party packages not available in kinetic (such as robot_upstart), at /usr/local/mybot/overlay
  3. a workspace containing my custom application and packages at /usr/local/mybot/ros

Each workspace builds fine when I run catkin_make inside them. However, I can't source their setup.bash scripts to expose all their packages to ROS.

I'm using:

  1. rospack list|grep -i actionlib to determine if the base Kinetic workspace is accessible, called check A.
  2. rospack list|grep -i upstart to determine if the second workspace is accessible, called check B.
  3. rospack list|grep -i mybot to determine if the third workspace is accessible, called check C.

If I run source /opt/ros/kinetic/setup.bash, then A passes, B fails, and C fails, as expected.

If I then run source /usr/local/mybot/overlay/devel/setup.bash, then A passes, B passes, and C fails, as expected.

If I then run source /usr/local/mybot/ros/devel/setup.bash, then A passes, B fails unexpectedly, but C passes.

So it seems that my third workspace is overwriting the environment set by the second workspace. How do I fix this?

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2016-07-04 11:04:43 -0600

Dirk Thomas gravatar image

Yes, it is possible to source multiple workspaces and use the combined environment of them. You can source a setup file and pass --extend which will extend the current environment (set by another workspace before) instead of "resetting" the environment.

Please see for more information.

edit flag offensive delete link more

answered 2016-07-03 14:09:51 -0600

ahendrix gravatar image

Workspaces don't extend the environment; they set it.

The first time you build a workspace, it captures the existing ROS environment and creates a setup file that overlays the new workspace on the existing environment variables. When you source the setup file from this workspace, it sets the environment variables to overlay this workspace on your previous environment.

This means that you only need to source one setup.bash for the workspace at the top of your set of overlays, and that it will always produce the same environment.

To build your overlay, you should:

  1. remove the build and devel directories from your workspaces, to reset them to a clean state
  2. source /opt/ros/kinetic/setup.bash and build workspace B
  3. source workspace B and build workspace C

To use your overlay, you just need to source the setup file in workspace C

If you need to make minor changes in workspace B, you can rebuild it with any environment, but if you need to to a complete rebuild of workspace B, you should source /opt/ros/kinetic/setup.bash before you do, so that you don't overlay it on your other workspaces.

edit flag offensive delete link more


It is possible to extend the environment rather then (re)setting it. Please see other answer.

Dirk Thomas gravatar image Dirk Thomas  ( 2016-07-04 11:05:40 -0600 )edit

Question Tools

1 follower


Asked: 2016-07-03 13:29:52 -0600

Seen: 3,049 times

Last updated: Jul 04 '16