ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A answers.ros.org

# How to set up catkin workspaces with packages?

I am confused about how to set up my catkin workspaces with my packages. Before, I had a directory where I put all of my ros packages (other than the ones in /opt/ros/version/share and stacks). Now with catkin...should I have a separate catkin workspace for each package or should I just have one catkin workspace where all of my packages are located?

The former makes more sense to me, but in the tutorials we make a workspace and then put the beginner_tutorials package in it. We also have to catkin_make at the root of the catkin workspace.

Why wouldn't we catkin_create the package and then make the root directory of the package a catkin workspace so we can catkin_make from there?

edit retag close merge delete

Sort by » oldest newest most voted

catkin workspaces are designed for building many packages together at once.

You should put related packages in the same workspace rather than building them separately. You might, however, put packages in separate workspaces in order to have a smaller, faster building workspace. For instance, if you built all of the packages for ros-desktop in one workspace, and then you created your package foo in the same workspace, it might become cumbersome to rebuild that entire, large workspace each time you make a change to foo. So instead you can put foo in a different workspace which builds on that one, so then you only have to rebuild foo.

You can build a single package by using the standard CMake way of building:

mkdir build
cd build
cmake ..
make


The catkin workspace helps you by not only building multiple packages at once, but also by building you packages in the correct order. Consider that you have packages foo and bar where foo depended on bar. In a catkin workspace, catkin will automatically build bar before foo for you.

When creating new packages I would recommend making a catkin workspace first:

mkdir ~/my_catkin_ws
cd ~/my_catkin_ws


Then I would make a src (source) directory in my workspace and create the packages there:

mkdir src
cd src
catkin_create_package foo bar roscpp tf etc...


Now you would be able to build foo by running catkin_make:

cd ~/my_catkin_ws
source /opt/ros/groovy/setup.bash  # You should source the workspace which contains the packages you depend on, often this will be in /opt/ros/groovy
catkin_make


Interestingly, catkin_make isn't doing anything fancy here. A catkin workspace is just a CMake project which can automatically find, include and use other packages. Because of this you can build a catkin workspace just like you can a single package:

cd ~/my_catkin_ws
cd src
catkin_init_workspace  # This creates a "top-level" CMakeLists.txt which collects and builds the packages in your workspace. Since this file is completely boiler plate this command just makes a symbolic link to the one provided by catkin
cd ..
mkdir build
cd build
cmake ../src  # Remember we put the source packages in that folder
make

more

Yes, I see the merit in it to build multiple packages and in the same order. But now if you wanted to create a new package that has nothing to do with foo or bar, would we put it in the same catkin_workspace? And if so, why?

( 2013-06-27 12:20:23 -0600 )edit
1

There is no harm in putting them in the same workspace, but by putting unrelated packages in different workspaces you will never have to spend time configuring or building foo or bar when all you're concerned about is building your package.

( 2013-06-27 12:22:35 -0600 )edit

I see. Thanks for updating the answer and helping me understand.

( 2013-06-27 12:29:21 -0600 )edit

## Stats

Seen: 2,113 times

Last updated: Jun 27 '13