Ask Your Question

How to solve 'file '' was not found in the share directory of package'?

asked 2019-12-09 05:35:21 -0500

sam gravatar image

updated 2019-12-09 05:37:05 -0500

I'm using ROS2 Dashing on ubuntu 18.04 64bits.

I have run:

cd ~/ros2_overlay_ws/src/
ros2 pkg create sam_empty_package_with_rviz2
cd ~/ros2_overlay_ws/src/sam_empty_package_with_rviz2
mkdir -p rviz2/
mkdir -p launch/

vim launch/

import os

from ament_index_python.packages import get_package_share_directory
from launch import LaunchDescription
from launch_ros.actions import Node

def generate_launch_description():
    rviz_config_dir = os.path.join(

    return LaunchDescription([
            arguments=['-d', rviz_config_dir],


colcon build --packages-select sam_empty_package_with_rviz2

After compile I run:

ros2 launch sam_empty_package_with_rviz2

And I got errors:

sam@sam-ub1804:~$ ros2 launch sam_empty_package_with_rviz2
file '' was not found in the share directory of package 'sam_empty_package_with_rviz2' which is at '/home/sam/ros2_dashing_overlay_ws/install/sam_empty_package_with_rviz2/share/sam_empty_package_with_rviz2'

How to solve it?

Thank you~

edit retag flag offensive close merge delete


Just making sure: have you sourced the correct setup.bash file after you built your workspace?

gvdhoorn gravatar image gvdhoorn  ( 2019-12-09 05:41:42 -0500 )edit

Also make sure you have something like this

install(DIRECTORY launch

in your CMakeLists.txt. Otherwise "colcon build" does not actually place your launchfiles in the share folder (which is where ros2 launch looks for launchfiles).

MCornelis gravatar image MCornelis  ( 2019-12-09 08:33:05 -0500 )edit

If you plan on changing the .rviz2 file and launchfile a lot I recommend building with --symlink-install. This way you don't have to source after every change to these 2 files.

MCornelis gravatar image MCornelis  ( 2019-12-09 08:36:14 -0500 )edit

I'm sure I have already sourced that setup.bash on my ROS2 workspace. And it works when I use that install. Thank you very much! Please post as an answer! Another simple question is why if I use --symlink-install, it will cause my rviz2 could not save file anymore?

sam gravatar image sam  ( 2019-12-10 02:12:11 -0500 )edit

A normal colcon build will copy the launch directory to the share directory. So if you then change something in the launch folder you have to colcon build again, otherwise the share directory is not updated (at least this is my understanding). If you do colcon build --symlink-install a link to the launch folder is placed in the share directory. So if you then update something in the launch folder even if you look in the share directory you will get the updated version. I am not aware of --symlink-install preventing you from saving the .rviz2 config. This is new to me, my bad I think :P? You are free to do a normal colcon build if that works for you, but like I said it will require rebuilding every time you change something to your or your .rviz2/.rviz file.

MCornelis gravatar image MCornelis  ( 2019-12-10 06:44:56 -0500 )edit

You can btw also make a config folder in one of your packages where you put the .rviz file and then do

install(DIRECTORY config

in the CMakeLists.txt. In your launch file you can then do something like

rviz_config_dir = os.path.join(
MCornelis gravatar image MCornelis  ( 2019-12-10 06:52:03 -0500 )edit

You can btw also just hit the up-arrow next to a comment. I believe this also gives me karma? You might even be able to accept a comment as an answer, I'm not entirely sure how this all works :P Just glad I was able to help ^^

MCornelis gravatar image MCornelis  ( 2019-12-10 06:55:11 -0500 )edit

Thanks for very detail information. I'm not able to set the comment as an answer. Please post your comment as an answer and I will mark it.

sam gravatar image sam  ( 2019-12-11 01:59:26 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2019-12-12 04:05:56 -0500

MCornelis gravatar image

As per request of the questioin poster I'll highlight the answer in the comments that worked for him here:

In CMakeLists.txt you need to put an install() command which basically tells colcon build to put either a copy or a link to a certain folder in the share directory. The share directory is the default place where ros2 launch will look for things. So if you add

install(DIRECTORY launch

To your CMakeLists.txt and then do a colcon build your share directory, so for instance ros2_ws/install/<pkg_name>/share/<pkg_name>/, will have a copy of your launch directory in it.

If you do colcon build --symlink-install, then instead of a copy of the launch file it will put a symbolic link to the launchfile. This means that if you change something to the launch file in your package you don't have to rebuild the package for the changes to take effect. This is only true for files that don require compilation, so --symlink-install will work for config files or python code / launch files etc.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2019-12-09 05:35:21 -0500

Seen: 506 times

Last updated: Dec 12 '19