4.2.1自定义服务接口构建功能包出错
-
```
code_textsensor_msgs/Image image --- int16 number float32 use_time int32[] top int32[] right int32[] bottom int32[] left
cmake_minimum_required(VERSION 3.8) project(chapt4_interfaces) if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") add_compile_options(-Wall -Wextra -Wpedantic) endif() # find dependencies find_package(ament_cmake REQUIRED) find_package(sensor_msgs REQUIRED) find_package(rosidl_default_generators REQUIRED) rosidl_generate_interfaces(${PROJECT_NAME} "srv/FaceDetector.srv" DEPENDENCIES sensor_msgs ) if(BUILD_TESTING) find_package(ament_lint_auto REQUIRED) # the following line skips the linter which checks for copyrights # comment the line when a copyright and license is added to all source files set(ament_cmake_copyright_FOUND TRUE) # the following line skips cpplint (only works in a git repo) # comment the line when this package is in a git repo and when # a copyright and license is added to all source files set(ament_cmake_cpplint_FOUND TRUE) ament_lint_auto_find_test_dependencies() endif() ament_package()
<?xml version="1.0"?> <?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?> <package format="3"> <name>chapt4_interfaces</name> <version>0.0.0</version> <description>TODO: Package description</description> <maintainer email="redfish@foxmail.com">yhy</maintainer> <license>Apache-2.0</license> <buildtool_depend>ament_cmake</buildtool_depend> <member_of_group>rosidl_interface_packages</member_of_group> <depend>sensor_msgs</depend> <depend>rosidl_default_generators</depend> <test_depend>ament_lint_auto</test_depend> <test_depend>ament_lint_common</test_depend> <export> <build_type>ament_cmake</build_type> </export> </package>
求解,一步步跟着教程来的,为什么会出现构建失败的情况
-
奇怪的是,我将xml文件中的<member_of_group>rosidl_interface_packages</member_of_group>改为<member_of_group>rosidl_interfaces_packages</member_of_group>后就能构建成功了,我使用的ROS2版本为humble,这就很奇怪
-
@因却斯丁 我这边是正常的,
/opt/ros/humble/share/rosidl_cmake/cmake/rosidl_generate_interfaces.cmake:229
的上下文如下(可以看到__group_name
的值是rosidl_interface_packages
):224 set(_group_name "rosidl_interface_packages") 225 if(NOT _AMENT_PACKAGE_NAME) 226 ament_package_xml() 227 endif() 228 if(NOT _group_name IN_LIST ${_AMENT_PACKAGE_NAME}_MEMBER_OF_GROUPS) 229 message(FATAL_ERROR 230 "Packages installing interfaces must include \ 231 '<member_of_group>${_group_name}</member_of_group>' \ 232 in their package.xml" 233 )
你这个确实有点奇怪。是不是没有执行
sudo apt upgrade
之类的导致的?我这个文件来自 apt 中的
ros-humble-rosidl-cmake
,其版本为3.1.7-1jammy.20250718.233348
,如下所示:wsxq2@ubuntu-pc:ros2_ws$ dpkg -S /opt/ros/humble/share/rosidl_cmake ros-humble-rosidl-cmake: /opt/ros/humble/share/rosidl_cmake wsxq2@ubuntu-pc:ros2_ws$ apt show ros-humble-rosidl-cmake Package: ros-humble-rosidl-cmake Version: 3.1.7-1jammy.20250718.233348 Priority: optional Section: misc Maintainer: Michel Hidalgo <michel@ekumenlabs.com> Installed-Size: 104 kB Depends: python3-empy, ros-humble-ament-cmake, ros-humble-rosidl-adapter, ros-humble-rosidl-parser, ros-humble-ros-workspace Download-Size: 15.7 kB APT-Manual-Installed: no APT-Sources: https://mirrors.tuna.tsinghua.edu.cn/ros2/ubuntu jammy/main amd64 Packages Description: The CMake functionality to invoke code generation for ROS interface files. wsxq2@ubuntu-pc:ros2_ws$ dpkg -l |grep ros-humble-rosidl-cmake ii ros-humble-rosidl-cmake 3.1.7-1jammy.20250718.233348 amd64 The CMake functionality to invoke code generation for ROS interface files. wsxq2@ubuntu-pc:ros2_ws$