0
$\begingroup$

Rosanswers logo

I've read many answers about how ROS sourcing works and I'm a bit confused on a couple things:

Can you source an overlay before building it?

This answer says you can add the following to your .bashrc:

source /opt/ros/indigo/setup.bash
source ~/catkin_ws/devel/setup.bash

However, the ROS2 tutorials say the following:

Before sourcing the overlay (your workspace), it is very important that you open a new terminal, separate from the one where you built the workspace. Sourcing an overlay in the same terminal where you built, or likewise building where an overlay is sourced, may create complex issues.

The first answer results in your overlay always being sourced every time you open a terminal. This contradicts the ROS2 tutorial that says you shouldn't source the overlay before building it.

Why do you need to source both /opt/ros/<distro>/setup.bash and ~/catkin_ws/devel/setup.bash?

I looked at the environment variables with printenv when I sourced both of them vs. just the latter and they were the same. It seems like you only need to source ~/catkin_ws/devel/setup.bash given that you have sourced /opt/ros/<distro>/setup.bash before running catkin_make.


Originally posted by EricW on ROS Answers with karma: 15 on 2021-02-06

Post score: 1

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

ROS 1 and ROS 2 cannot necessarily be compared when it comes to environment setup. So whatever you read for ROS 1, does not necessarily translate to ROS 2.

re: why source both: you don't need to. It's a pattern I see often mentioned, but it's not needed.

Having those two lines in your .bashrc does provide some convenience though: if $HOME/catkin_ws exists and has been built, it will result in that workspace getting sourced. If it doesn't, you'll at least get the base ROS environment sourced.

So I guess it's more about convenience than necessity.


Originally posted by gvdhoorn with karma: 86574 on 2021-02-07

This answer was ACCEPTED on the original site

Post score: 2


Original comments

Comment by EricW on 2021-02-07:
Thanks so much for clearing that up! As a small follow-up, is there any detriment to sourcing multiple workspaces with --extend in your .bashrc (ex. source ~/catkin_ws && source ~/other_ws --extend)? This seems like it would let you access packages from both workspaces, but I'm not sure if there's any reason not to do this

Comment by gvdhoorn on 2021-02-07:
It's not a good idea to ask follow-up questions as comments under questions with accepted answers. They have very little visibility.

It would be better to post a new question -- after having made sure there isn't already a question about the same topic of course (use Google: add site:answers.ros.org to your query).

Comment by EricW on 2021-02-07:
Got it. Thanks for the help! Found a good answer here. I had read it before, but coming back to it fresh, it made a lot more sense

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.