ROS2 ERROR
长篇error合集,请善用搜索功能
1. CMake Error at /opt/ros/humble/share/rosidl_cmake/cmake/rosidl_generate_interfaces.cmake:213 (add_custom_target)
CMake Error at /opt/ros/humble/share/rosidl_cmake/cmake/rosidl_generate_interfaces.cmake:213 (add_custom_target):
The target name "$(PROJECT_NAME)" is reserved or not valid for certain
CMake features, such as generator expressions, and may result in undefined
behavior.
Call Stack (most recent call first):
CMakeLists.txt:15 (rosidl_generate_interfaces)
原文:
rosidl_generate_interfaces( $(PROJECT_NAME)
"msg/Student.msg"
)
改成:
rosidl_generate_interfaces( ${PROJECT_NAME}
"msg/Student.msg"
)
2. std::runtime_error
在运行ros2 run cpp01_topic demo04_listener_stu
时报错:
terminate called after throwing an instance of 'std::runtime_error'
what(): this specialization of rclcpp::get_message_type_support_handle() should never be called
[ros2run]: Aborted
重新编译后发现一个警告
[0.291s] WARNING:colcon.colcon_core.package_selection:Some selected packages are already built in one or more underlay workspaces:
'base_interfaces_demo' is in: /home/nightfall/ros2/ws01_plumbing/install/base_interfaces_demo
If a package in a merged underlay workspace is overridden and it installs headers, then all packages in the overlay must sort their include directories by workspace order. Failure to do so may result in build failures or undefined behavior at run time.
# 如果合并的底层工作空间中的包被覆盖并安装标头,则覆盖层中的所有包都必须按工作空间顺序对它们的包含目录进行排序。 如果不这样做,可能会导致构建失败或运行时出现未定义的行为。
If the overridden package is used by another package in any underlay, then the overriding package in the overlay must be API and ABI compatible or undefined behavior at run time may occur.
# 如果被覆盖的包被任何底层中的另一个包使用,则覆盖中的覆盖包必须与 API 和 ABI 兼容,否则可能会在运行时发生未定义的行为。
If you understand the risks and want to override a package anyways, add the following to the command line:
--allow-overriding base_interfaces_demo
# 如果您了解风险并且无论如何都想覆盖包,请将以下内容添加到命令行:
# --allow-overriding base_interfaces_demo
This may be promoted to an error in a future release of colcon-override-check.
# 这可能会在未来版本的 colcon-override-check 中升级为错误。
可知正是因为这个才会在run时报错,故重新编译
3.在使用clangd进行代码补全时,新包含库频繁报错
很可能是错误的colcon build导致
因为在ROS2中,在工作空间的src目录下用colcon build进行编译时不会像ROS一样报错,是可成功执行的,这样会导致所包含库错乱,src目录下出现include、build、install文件夹。
改正方法
将所有include、build、install文件全部删除,将整个工作空间重新编译
4. 404 Not Found E: 仓库 “····”没有 Release 文件
错误:10 https://ppa.launchpadcontent.net/shawn-p-huang/ppa/ubuntu jammy Release
404 Not Found [IP: 185.125.190.52 443]
正在读取软件包列表… 完成
E: 仓库 “https://ppa.launchpadcontent.net/shawn-p-huang/ppa/ubuntu jammy Release” 没有 Release 文件。
N: 无法安全地用该源进行更新,所以默认禁用该源。
N: 参见 apt-secure(8) 手册以了解仓库创建和用户配置方面的细节。
**分析:**查阅资料后发现只有中科大的源有对应的Jammy版本,可能是前期随便换源导致的
解决方法:
删除报错的文件,目前未对环境产生影响
cd /etc/apt/sources.list.d/
ls
sudo rm shawn-p-huang-ubuntu-ppa-jammy.list shawn-p-huang-ubuntu-ppa-jammy.list.save
最终结果如下:
写在最后:
实现在Ubuntu22.04, ros2 humble+vscode
学习过程使用B站赵虚左老师的课程,但vscode使用clangd进行代码补全,并安装llvm+clang,具体参考:Linux下使用VScode开发ROS时clangd插件的使用
引申出博客针对ROS2的改动:对于4.2,应将 set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
添加到每个功能包的cmakelist.txt文件中