紧急通知:禁止一切关于政治&VPN翻墙等话题,发现相关帖子会立马删除封号
小鱼 ROS 2 新书上线!点击链接查看, 新书配套视频点击链接查看。
提问前必看的发帖注意事项—— 提问前必看!不符合要求的问题拒绝回答!!
社区使用指南—如何添加标签修改密码
小鱼 ROS 2 新书上线!点击链接查看, 新书配套视频点击链接查看。
提问前必看的发帖注意事项—— 提问前必看!不符合要求的问题拒绝回答!!
社区使用指南—如何添加标签修改密码
ROS2 humble 编译自定义话题接口报错
-
ubuntu 22.02 双系统
ROS2 humble
根据赵虚左的视频教程建立工作空间、功能包base_interfaces_demo,无其他依赖,建立msg文件夹并编写Student.msg文件
Student.msg文件:string name int32 age float64 height
package.xml文件(添加了三项依赖):
<?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>base_interfaces_demo</name> <version>0.0.0</version> <description>TODO: Package description</description> <maintainer email="wuwenxiang@todo.todo">wuwenxiang</maintainer> <license>TODO: License declaration</license> <buildtool_depend>ament_cmake</buildtool_depend> <build_depend>rosidl_default_generators</build_depend> <exec_depend>rosidl_default_runtime</exec_depend> <member_of_group>rosidl_interface_packages</member_of_group> <export> <build_type>ament_cmake</build_type> </export> </package>
CMakeList.txt文件:
cmake_minimum_required(VERSION 3.8) project(base_interfaces_demo) 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) # uncomment the following section in order to fill in # further dependencies manually. find_package(rosidl_default_generators REQUIRED) rosidl_generate_interfaces(${PROJECT_NAME} "msg/Student.msg" ) 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()
colcon build编译后报错:
Starting >>> pkg01_helloworld_cpp --- stderr: base_interfaces_demo CMake Error at /opt/ros/humble/share/rosidl_cmake/cmake/rosidl_generate_interfaces.cmake:240 (list): list index: 1 out of range (-1, 0) Call Stack (most recent call first): CMakeLists.txt:14 (rosidl_generate_interfaces) CMake Error at /opt/ros/humble/share/rosidl_generator_c/cmake/rosidl_generator_c_generate_interfaces.cmake:69 (message): Target dependency '/ros/ws01/build/base_interfaces_demo/rosidl_adapter/base_interfaces_demo/msg/Student.idl' does not exist Call Stack (most recent call first): /opt/ros/humble/share/ament_cmake_core/cmake/core/ament_execute_extensions.cmake:48 (include) /opt/ros/humble/share/rosidl_cmake/cmake/rosidl_generate_interfaces.cmake:286 (ament_execute_extensions) CMakeLists.txt:14 (rosidl_generate_interfaces) --- Failed <<< base_interfaces_demo [0.97s, exited with code 1]
报错中
Target dependency '/ros/ws01/build/base_interfaces_demo/rosidl_adapter/base_interfaces_demo/msg/Student.idl' does not exist
该Student.idl在工作空间ws01/build/base_interfaces_demo/rosidl_adapter/base_interfaces_demo/msg/下可以找到,发现报错的路径前缀居然是从根目录/开始的,所以尝试将整个文件夹复制到根目录下/,删除掉build文件夹后重新编译,居然通过了。
查看报错中的/opt/ros/humble/share/rosidl_generator_c/cmake/rosidl_generator_c_generate_interfaces.cmake文件,产生报错的地方set(target_dependencies "${rosidl_generator_c_BIN}" ${rosidl_generator_c_GENERATOR_FILES} "${rosidl_generator_c_TEMPLATE_DIR}/action__type_support.h.em" "${rosidl_generator_c_TEMPLATE_DIR}/idl.h.em" "${rosidl_generator_c_TEMPLATE_DIR}/idl__functions.c.em" "${rosidl_generator_c_TEMPLATE_DIR}/idl__functions.h.em" "${rosidl_generator_c_TEMPLATE_DIR}/idl__struct.h.em" "${rosidl_generator_c_TEMPLATE_DIR}/idl__type_support.h.em" "${rosidl_generator_c_TEMPLATE_DIR}/msg__functions.c.em" "${rosidl_generator_c_TEMPLATE_DIR}/msg__functions.h.em" "${rosidl_generator_c_TEMPLATE_DIR}/msg__struct.h.em" "${rosidl_generator_c_TEMPLATE_DIR}/msg__type_support.h.em" "${rosidl_generator_c_TEMPLATE_DIR}/srv__type_support.h.em" ${rosidl_generate_interfaces_ABS_IDL_FILES} ${_dependency_files}) foreach(dep ${target_dependencies}) if(NOT EXISTS "${dep}") message(FATAL_ERROR "Target dependency '${dep}' does not exist") endif() endforeach()
怀疑是这几个变量有bug
-
@2099684574 应该是工作空间搞混了,建议删除所有编译相关文件重新测试
-
@小鱼 我懂了,是路径里有中文,所以${rosidl_generate_interfaces_ABS_IDL_FILES}这个变量中中文字段缺少,文件路径就错了
之前看到论坛里有个类似的问题,报错和我一样,估计也是这个原因