ROS2 executes the source setup.bash command to report errors and solutions

1. Error type

After compiling the ros2 package, execute it on the terminal

source path/to/your/workspace/install/setup.bash

An error is reported:

not found: "path/to/your/workspace/install/pkg_name/share/pkg_name/local_setup.bash"

2. The cause and solution of the problem

This is because there is no statement in CMakeLists.txt ament_package(), ament_package()the function is to declare that your package is a ros2 package, and the function of this command is catkin_package()similar to that in ros1.
If this statement is not added, colcon will not compile the package into a ros2 package, so source install/setup.bashthe relevant setup.bash file will not be found during execution.

ament_package()Statements can be added anywhere in CMakeLists.txt, but must be placed find_package(ament_cmake REQUIRED)after the statement. Otherwise Cmake cannot find the ament_package command.

Guess you like

Origin blog.csdn.net/qq_38222947/article/details/131141926