Hi. There are 2 ways to solve this issue. You can place your source /opt/ros/melodic/setup.bash
in your bashrc file and delete the build
and devel
folders of your catkin workspace and try rebuilding your workspace with catkin_make
. If for some strange reason this doesnt work (it really should), you can utilize the --extend
parameter of the source command to source more than 1 file. The source
command generally overwrites one another in the sense that if you have 2 separate cakin workspaces A and B, if you perform source devel/setup.bash
in workspace A and then perform source devel/setup.bash
in workspace B, the second command will override the first command and the packages in workspace A will not be available to you.
To overcome this, in workspace A, perform source devel/setup.bash
as usual but after this, going into workspace B ensure to perform source devel/setup.bash --extend
and now packages from both workspaces will be enabled. In a similar light, perhaps you could try source /opt/ros/melodic/setup.bash
and then source devel/setup.bash --extend
in your workspace. But solution 1 should also work for you.
Hope that helps.
Originally posted by hashirzahir with karma: 228 on 2020-04-13
This answer was ACCEPTED on the original site
Post score: 2
Original comments
Comment by sverre on 2020-04-13:
Thanks a lot! :D Deleting the build and devil folders worked :) When I ran catkin_make I got en error that it could not locate one of the headers that were generated by actionlib (even though it was there), the error did not show up the second time I built. Just in case someone experiences something similar
Comment by sverre on 2020-04-13:
A follow-up question since only one source command can be run at once. Should then only the catkin_ws/devel/setup.bash
be sourced in .bashrc
, or only /opt/ros/melodic/setup.bash
? I guess the first since that one is required to be able to see your project files? Does this setup include the things melodic setup does?
Comment by hashirzahir on 2020-04-13:
It is good practice to only keep the /opt/ros/melodic/setup.bash
in the bashrc. Workspace sources should be sourced when necessary in the terminal. The --extend option is more for getting the packages from 2 local catkin workspaces on your computer. This is generally done to avoid any strange behaviour that may happen if there are conflicting package names or types in your various local workspaces. But if you only have 1 local catkin workspace on your computer, it is also okay to put your catkin_ws/devel/setup.bash
in the bashrc for added speed. But what I tend to do is to add an alias like alias source_ws_a=source ~/a_ws/devel/setup.bash
so that it is quick for me to source the appropriate packages.
Comment by Geronimo on 2021-09-30:
so this happens to me every time I restart my machine, so does that really mean I'm supposed to be deleting devel and build whennever I restart my machine? What is the permanent fix? I looked at the code devel/setup.sh code and it seems to just be blanking out a bunch of params which is probably why catkin_make doesn't work. Should I just be directly setting the ROS_PACKAGE_PATH to include the workspace/src as well? I think that makes the package building work.
and if I put the catkin_ws/devel/setup.bash in my bashrc it blanks everything out like the OPs original message
Comment by gvdhoorn on 2021-09-30:
Manually setting ROS_PACKAGE_PATH
is not needed. Cleaning out your workspace is not needed.
If you can't get the normal workflow to work, something is setup incorrectly. You should try to figure out what, instead of addressing the symptoms.
Post a new question, don't post additional questions under questions with answers from over a year go.