You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

ROS2自定义SRV接口编译报错:rosidl_generate_interface相关CMake错误

geometry_msgs/PoseStamped output1

### msg文件夹下的`.msg`文件内容

sensor_msgs/Imu msg1

### CMakeLists.txt内容
```cmake
cmake_minimum_required(VERSION 3.8)
project(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)
# uncomment the following section in order to fill in
# further dependencies manually.
# find_package(<dependency> REQUIRED)

find_package(geometry_msgs REQUIRED)
find_package(sensor_msgs REQUIRED) 
find_package(rosidl_default_generators REQUIRED)

rosidl_generate_interfaces(${PROJECT_NAME}
  "srv/WifiGeo.srv"
  "msg/WifiData.msg"
  DEPENDENCIES geometry_msgs sensor_msgs)# Add packages that above messages depend on

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()

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>interfaces</name>
  <version>0.0.0</version>
  <description>Interface for topics and services</description>
  <maintainer email="email">nyongcyongs98</maintainer>
  <license>TODO: License declaration</license>

  <buildtool_depend>ament_cmake</buildtool_depend>
  
  <depend>geometry_msgs</depend>
  <depend>sensor_msgs</depend>

  <build_depend>rosidl_default_generators</build_depend>

  <exec_depend>rosidl_default_runtime</exec_depend>

  <member_of_group>rosidl_interface_packages</member_of_group>

  <test_depend>ament_lint_auto</test_depend>
  <test_depend>ament_lint_common</test_depend>

  <export>
    <build_type>ament_cmake</build_type>
  </export>
</package>

具体问题

回到工作空间根目录运行colcon build时,出现如下错误:

Starting >>> interfaces
Starting >>> rssi
--- stderr: interfaces                                                   
CMake Error at /opt/ros/humble/share/rosidl_adapter/cmake/rosidl_adapt_interfaces.cmake:42 (get_executable_path):
  Unknown CMake command "get_executable_path".
Call Stack (most recent call first):
  /opt/ros/humble/share/rosidl_cmake/cmake/rosidl_generate_interfaces.cmake:130 (rosidl_adapt_interfaces)
  CMakeLists.txt:18 (rosidl_generate_interfaces)


---
Failed <<< interfaces [0.73s, exited with code 1]
Aborted <<< rssi [0.75s]

Summary: 0 packages finished [1.14s]
  1 package failed: interfaces
  1 package aborted: rssi
  2 packages had stderr output: interfaces rssi
  1 package not processed

我已经在网上搜索许久,未发现他人遇到该错误,猜测可能是rosidl_generate_interface的部分函数已被弃用,求解答!


解答

这个错误的根源是get_executable_path是CMake 3.19及以上版本才引入的命令,而你的CMakeLists.txt开头指定的最低CMake版本是3.8。CMake会以兼容旧版本的模式运行,导致无法识别这个新命令。

解决步骤:

  1. 打开接口包的CMakeLists.txt,将第一行的cmake_minimum_required(VERSION 3.8)修改为cmake_minimum_required(VERSION 3.19)(Ubuntu 22.04默认的CMake版本是3.22,完全满足要求)
  2. 清理之前的编译缓存:rm -rf build/ install/ log/
  3. 重新编译接口包:colcon build --packages-select interfaces

完成后即可正常编译,后续再编译整个工作空间也不会有问题。


内容的提问来源于stack exchange,提问作者nyongcyongs98

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.04 15:50:21