安装 colcon : sudo apt install python3-colcon-common-extensions
。 ROS2的build没有了ROS1中的devel概念
与ROS1不同,如果一个包不放在src
目录,而放在工作空间目录,colcon也会编译它。
colcon build 编译所有包
colcon build —packages-select pkg 只编译一个包
colcon build --packages-select
指令并不会编译该包的依赖,往往会报错。可以用下面这条指令进行包和其依赖编译
1 | colcon build --packages-up-to package_name |
- colcon build —cmake-args -DCMAKE_BUILD_TYPE=Release
不编译测试单元
colcon test --packages-select YOUR_PKG_NAME --cmake-args -DBUILD_TESTING = 0
运行编译的包的测试
colcon test
- 允许通过更改src下的部分文件改变install,这样每次修改Python脚本时不必重新 build
colcon build --symlink-install
colcon build —symlink-install pkg
colcon build —symlink-install —packages-ignore pkg
减小colcon的CPU占用
指定并行的线程数1
colcon build --symlink-install --parallel-workers 1
不使用并行编译1
colcon build --symlink-install --executor sequential
两种编译不要混合用,否则每次都会重新编译
显示CMake中的MESSAGE
colcon build —event-handlers console_direct+ —packages-select test_node
console_direct
换成 console_cohesion
也可以
如果不想编译特定的包,在该包目录里面创建一个名为COLCON_IGNORE
文件,这样子这个包就不会被索引到了
问题
- 编译时报错 CMake Error at /opt/ros/jazzy/share/rosidl_typesupport_c/cmake/get_used_typesupports.cmake:35 (message):
No ‘rosidl_typesupport_c’ found
执行source后再编译
一开始我以为是/opt
里的安装有问题,后来发现是ament_target_dependencies
里没有添加nav_msgs
,导致include
头文件时会找不到
- failed to create symbolic link ‘/home/xxx/learning_interfaces2’ because existing path cannot be removed: Is a directory
把对应的目录删掉
- CMake Warning: Manually-specified variables were not used by the project: CATKIN_INSTALL_INTO_PREFIX_ROOT
在相应的包里加入1
2
3<export>
<build_type>ament_cmake</build_type>
</export>
- 如果需要在包的package.xml中添加依赖关系。比如sample包依赖common包,那么就在sample包的package.xml中添加
1 | <depend>common</depend> |
告诉编译器,编译B包的时候依赖A包,A包需要先编译出来。
- 没有那个文件或目录
1 | Starting >>> test_node |
删掉build
目录中的test_node
文件夹
- 编译自定义的msg包时,报错 找不到rosidl_typesupport_c
一般都安装了相应的库:1
sudo apt install ros-jazzy-rosidl-typesupport-c
source /opt/ros/jazzy/setup.bash
即可
- CMake Warning: Manually-specified variables were not used by the project: CATKIN_INSTALL_INTO_PREFIX_ROOT
相应的包里明明没有用CATKIN
相关的东西,不知是哪里报警,只好在CMake里加一句 unset( CATKIN_INSTALL_INTO_PREFIX_ROOT )
- 编译时找不到 ament_cmake
source /opt/ros/jazzy/setup.bash
- 报警: WARNING:colcon.colcon_ros.prefix_path.catkin:The path ‘/home/user/catkin_ws/install/nav2_map_server’ in the environment variable CMAKE_PREFIX_PATH doesn’t exist
即使删除了install
, build
, log
也无法解决,要想彻底解决只能重建一个工作空间。或者用临时方法,但新终端又会失效1
2unset AMENT_PREFIX_PATH
unset CMAKE_PREFIX_PATH
- 包的依赖问题
在路径 /build/my_package/ament_cmake_core
可以看到编译一个包后生成的cmake文件,比如my_packageConfig.cmake
和 my_packageConfig-version.cmake
如果包A需要包B,编译时报错找不到BConfig.cmake
,在工作空间执行 source