鱼香ROS社区
    • 版块
    • 最新
    • 未解决
    • 已解决
    • 群组
    • 注册
    • 登录
    紧急通知:禁止一切关于政治&VPN翻墙等话题,发现相关帖子会立马删除封号
    提问前必看的发帖注意事项: 社区问答规则(小鱼个人)更新 | 高质量帖子发布指南

    CPP节点使用interface包中服务在编译时提示无法找到target

    已定时 已固定 已锁定 已移动 未解决
    综合问题
    服务接口、 cmake error
    2
    3
    285
    正在加载更多帖子
    • 从旧到新
    • 从新到旧
    • 最多赞同
    回复
    • 在新帖中回复
    登录后回复
    此主题已被删除。只有拥有主题管理权限的用户可以查看。
    • W
      yqw
      最后由 编辑

      问题描述:
      在学习课程中服务例程时,王二节点使用了interface包中的服务接口,参照例程修改代码后编译一直报错,下面时详细的报错内容:

      Starting >>> cun_wang
      --- stderr: cun_wang
      CMake Warning (dev) at /opt/ros/foxy/share/ament_cmake_core/cmake/core/python.cmake:22 (find_package):
      Policy CMP0148 is not set: The FindPythonInterp and FindPythonLibs modules
      are removed. Run "cmake --help-policy CMP0148" for policy details. Use
      the cmake_policy command to set the policy and suppress this warning.

      Call Stack (most recent call first):
      /opt/ros/foxy/share/ament_cmake_core/cmake/core/all.cmake:53 (include)
      /opt/ros/foxy/share/ament_cmake_core/cmake/ament_cmake_core-extras.cmake:17 (include)
      /opt/ros/foxy/share/ament_cmake_core/cmake/ament_cmake_coreConfig.cmake:41 (include)
      /opt/ros/foxy/share/ament_cmake/cmake/ament_cmake_export_dependencies-extras.cmake:15 (find_package)
      /opt/ros/foxy/share/ament_cmake/cmake/ament_cmakeConfig.cmake:41 (include)
      CMakeLists.txt:19 (find_package)
      This warning is for project developers. Use -Wno-dev to suppress it.

      CMake Error at /home/wyq/ros_ws/happtown_ws/install/cun_interface/share/cun_interface/cmake/ament_cmake_export_targets-extras.cmake:18 (message):
      Failed to find exported target names in
      '/home/wyq/ros_ws/happtown_ws/install/cun_interface/share/cun_interface/cmake/cun_interface__rosidl_generator_cExport.cmake'
      Call Stack (most recent call first):
      /home/wyq/ros_ws/happtown_ws/install/cun_interface/share/cun_interface/cmake/cun_interfaceConfig.cmake:41 (include)
      CMakeLists.txt:21 (find_package)

      make: *** [Makefile:267: cmake_check_build_system] Error 1

      Failed <<< cun_wang [1.66s, exited with code 2]

      Summary: 0 packages finished [1.75s]
      1 package failed: cun_wang
      1 package had stderr output: cun_wang

      主要报错内容为Cmake无法找到target,见下文:
      CMake Error at /home/wyq/ros_ws/happtown_ws/install/cun_interface/share/cun_interface/cmake/ament_cmake_export_targets-extras.cmake:18 (message):
      Failed to find exported target names in '/home/wyq/ros_ws/happtown_ws/install/cun_interface/share/cun_interface/cmake/cun_interface__rosidl_generator_cExport.cmake'

      CmakeList.txt和package.xml都检查过了,没发现异常,尝试过新建其他interface包,也不行,请各位帮忙看下,谢谢

      1 条回复 最后回复 回复 引用 0
      • 小伊小
        机器人小伊
        最后由 编辑

        根据您提供的报错信息,CMake在尝试查找由cun_interface包导出的目标时遇到了问题。报错的关键部分指出CMake无法在给定的cun_interface__rosidl_generator_cExport.cmake文件中找到导出的目标名称。

        这通常意味着cun_interface包可能没有正确安装,或者安装过程中发生了某些错误,导致CMake无法找到必要的目标。以下是一些可能的解决步骤:

        1. 重新构建cun_interface包:

          • 确保cun_interface包的CMakeLists.txt和package.xml文件都是正确的,并且遵循了ROS 2的规范。
          • 清理cun_interface包的构建目录(通常是build和install目录)。
          • 重新在cun_interface包的根目录下运行colcon build(或您使用的其他构建工具)。
          • 确保构建过程中没有错误,并且cun_interface包成功安装。
        2. 检查ROS 2环境变量:

          • 确保您的工作空间已经被源化(source)。您可以在工作空间的根目录下运行source install/setup.bash(或对应的shell)。
          • 检查ROS_PACKAGE_PATH环境变量是否包含了cun_interface包的路径。
        3. 检查ament_export_targets:

          • 在cun_interface包的CMakeLists.txt中,确保您使用了ament_export_targets来导出目标。
          • 如果cun_interface包是一个接口包,它应该导出由rosidl_generate_interfaces生成的目标。
        4. 检查ROS 2版本和工具链:

          • 确保您使用的ROS 2版本(如Foxy)与您的工具链(如colcon)是兼容的。
          • 检查您是否有必要的依赖项和工具安装,比如python3-colcon-common-extensions。
        5. 清理并重新构建整个工作空间:

          • 有时候,整个工作空间的构建状态可能会变得不一致。您可以尝试清理整个工作空间(删除所有build和install目录),然后重新构建整个工作空间。
        6. 检查ROS 2的CMake模块:

          • 报错信息中还提到了关于FindPythonInterp和FindPythonLibs模块的警告。这通常与CMake策略CMP0148有关,但通常不会直接导致目标找不到的问题。不过,确保您的CMake版本与ROS 2兼容,并且所有必要的Python模块都已安装。

        如果上述步骤都无法解决问题,您可能需要更详细地检查cun_interface包的构建输出,看看是否有更具体的错误信息。此外,您还可以尝试在ROS 2社区论坛或相关GitHub仓库中寻求帮助,那里可能有其他开发者遇到过类似的问题。


        以上为生成回答,仅供参考~

        我是小伊,已接入ChatGpt,所有回复,仅供参考~

        W 1 条回复 最后回复 回复 引用 0
        • W
          yqw @小伊
          最后由 编辑

          @小鱼 我下载了教程中的src,编译时village_wang时依然是同样的问题,找不到"village_interface"包,另外,我的~/.bashrc设置如下:
          source /opt/ros/foxy/setup.bash
          source ~/ros_ws/happtown_ws/install/setup.bash
          工作空间目录为~/ros_ws/happtown_ws,帮你看下问题出在哪,谢谢

          1 条回复 最后回复 回复 引用 0
          • 第一个帖子
            最后一个帖子
          皖ICP备16016415号-7
          Powered by NodeBB | 鱼香ROS