Example 2.6 doesn't run as well


When I execute this command in the example:
ros2 launch my_package my_package_launch_file.launch.py

I get this message:
file ‘my_package_launch_file.launch.py’ was not found in the share directory of package ‘my_package’ which is at ‘/home/user/ros2_ws/install/my_package/share/my_package’

and not the output you’re saying I’m suppose to get.

any ideas why?


Did you get the permission to execute the file?
if not just run : chmod +x my_package_launch_file.launch.py
I think this is the issue.

Yeah I already did.

And also checked it worked with ls -la command

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.

Does it help?