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 iscatkin_package()
similar to that in ros1.
If this statement is not added, colcon will not compile the package into a ros2 package, sosource install/setup.bash
the relevant setup.bash file will not be found during execution.
ament_package()
Statements can be added anywhere in CMakeLists.txt, but must be placedfind_package(ament_cmake REQUIRED)
after the statement. Otherwise Cmake cannot find the ament_package command.