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

    colcon build失败 提示:CMake Error: The source directory "/opt/ros/humble/share/gtest_vendor" does not appear to contain CMakeLists.txt.

    已定时 已固定 已锁定 已移动 未解决
    综合问题
    colcon build报错 gtestvendor
    2
    3
    1.5k
    正在加载更多帖子
    • 从旧到新
    • 从新到旧
    • 最多赞同
    回复
    • 在新帖中回复
    登录后回复
    此主题已被删除。只有拥有主题管理权限的用户可以查看。
    • Q
      qic
      最后由 qic 编辑

      root@cq-virtual-machine:/opt/ros/humble# colcon build
      Starting >>> ament_package
      Starting >>> ament_lint
      Starting >>> gtest_vendor
      Starting >>> gtest
      Starting >>> ament_pycodestyle
      Starting >>> ament_cppcheck
      Starting >>> osrf_pycommon
      Starting >>> google_benchmark_vendor
      [2.564s] WARNING:colcon.colcon_ros.task.ament_python.build:Package 'ament_package' doesn't explicitly install a marker in the package index (colcon-ros currently does it implicitly but that fallback will be removed in the future)
      [2.564s] WARNING:colcon.colcon_ros.task.ament_python.build:Package 'ament_package' doesn't explicitly install the 'package.xml' file (colcon-ros currently does it implicitly but that fallback will be removed in the future)
      [2.568s] WARNING:colcon.colcon_ros.task.ament_python.build:Package 'ament_lint' doesn't explicitly install a marker in the package index (colcon-ros currently does it implicitly but that fallback will be removed in the future)
      [2.568s] WARNING:colcon.colcon_ros.task.ament_python.build:Package 'ament_lint' doesn't explicitly install the 'package.xml' file (colcon-ros currently does it implicitly but that fallback will be removed in the future)
      [2.586s] WARNING:colcon.colcon_ros.task.ament_python.build:Package 'ament_pycodestyle' doesn't explicitly install a marker in the package index (colcon-ros currently does it implicitly but that fallback will be removed in the future)
      [2.586s] WARNING:colcon.colcon_ros.task.ament_python.build:Package 'ament_pycodestyle' doesn't explicitly install the 'package.xml' file (colcon-ros currently does it implicitly but that fallback will be removed in the future)
      [2.593s] WARNING:colcon.colcon_ros.task.ament_python.build:Package 'ament_cppcheck' doesn't explicitly install a marker in the package index (colcon-ros currently does it implicitly but that fallback will be removed in the future)
      [2.595s] WARNING:colcon.colcon_ros.task.ament_python.build:Package 'ament_cppcheck' doesn't explicitly install the 'package.xml' file (colcon-ros currently does it implicitly but that fallback will be removed in the future)
      [2.599s] WARNING:colcon.colcon_ros.task.ament_python.build:Package 'osrf_pycommon' doesn't explicitly install a marker in the package index (colcon-ros currently does it implicitly but that fallback will be removed in the future)
      [2.599s] WARNING:colcon.colcon_ros.task.ament_python.build:Package 'osrf_pycommon' doesn't explicitly install the 'package.xml' file (colcon-ros currently does it implicitly but that fallback will be removed in the future)
      --- stderr: gtest_vendor
      CMake Error: The source directory "/opt/ros/humble/share/gtest_vendor" does not appear to contain CMakeLists.txt.
      Specify --help for usage, or press the help button on the CMake GUI.

      Failed <<< gtest_vendor [0.12s, exited with code 1]
      Aborted <<< google_benchmark_vendor [0.10s]
      Aborted <<< ament_package [0.14s]
      Aborted <<< ament_cppcheck [0.11s]
      Aborted <<< ament_lint [0.13s]
      Aborted <<< ament_pycodestyle [0.12s]
      Aborted <<< osrf_pycommon [0.11s]
      Aborted <<< gtest [0.34s]

      Summary: 0 packages finished [2.78s]
      1 package failed: gtest_vendor
      7 packages aborted: ament_cppcheck ament_lint ament_package ament_pycodestyle google_benchmark_vendor gtest osrf_pycommon
      2 packages had stderr output: google_benchmark_vendor gtest_vendor
      290 packages not processed

      凄凉的泪水凄 1 条回复 最后回复 回复 引用 0
      • 凄凉的泪水凄
        凄凉的泪水 @qic
        最后由 编辑

        @qic 在 colcon build失败 提示:CMake Error: The source directory "/opt/ros/humble/share/gtest_vendor" does not appear to contain CMakeLists.txt. 中说:

        root@cq-virtual-machine:/opt/ros/humble# colcon build
        Starting >>> ament_package
        Starting >>> ament_lint
        Starting >>> gtest_vendor
        Starting >>> gtest
        Starting >>> ament_pycodestyle
        Starting >>> ament_cppcheck
        Starting >>> osrf_pycommon
        Starting >>> google_benchmark_vendor
        [2.564s] WARNING:colcon.colcon_ros.task.ament_python.build:Package 'ament_package' doesn't explicitly install a marker in the package index (colcon-ros currently does it implicitly but that fallback will be removed in the future)
        [2.564s] WARNING:colcon.colcon_ros.task.ament_python.build:Package 'ament_package' doesn't explicitly install the 'package.xml' file (colcon-ros currently does it implicitly but that fallback will be removed in the future)
        [2.568s] WARNING:colcon.colcon_ros.task.ament_python.build:Package 'ament_lint' doesn't explicitly install a marker in the package index (colcon-ros currently does it implicitly but that fallback will be removed in the future)
        [2.568s] WARNING:colcon.colcon_ros.task.ament_python.build:Package 'ament_lint' doesn't explicitly install the 'package.xml' file (colcon-ros currently does it implicitly but that fallback will be removed in the future)
        [2.586s] WARNING:colcon.colcon_ros.task.ament_python.build:Package 'ament_pycodestyle' doesn't explicitly install a marker in the package index (colcon-ros currently does it implicitly but that fallback will be removed in the future)
        [2.586s] WARNING:colcon.colcon_ros.task.ament_python.build:Package 'ament_pycodestyle' doesn't explicitly install the 'package.xml' file (colcon-ros currently does it implicitly but that fallback will be removed in the future)
        [2.593s] WARNING:colcon.colcon_ros.task.ament_python.build:Package 'ament_cppcheck' doesn't explicitly install a marker in the package index (colcon-ros currently does it implicitly but that fallback will be removed in the future)
        [2.595s] WARNING:colcon.colcon_ros.task.ament_python.build:Package 'ament_cppcheck' doesn't explicitly install the 'package.xml' file (colcon-ros currently does it implicitly but that fallback will be removed in the future)
        [2.599s] WARNING:colcon.colcon_ros.task.ament_python.build:Package 'osrf_pycommon' doesn't explicitly install a marker in the package index (colcon-ros currently does it implicitly but that fallback will be removed in the future)
        [2.599s] WARNING:colcon.colcon_ros.task.ament_python.build:Package 'osrf_pycommon' doesn't explicitly install the 'package.xml' file (colcon-ros currently does it implicitly but that fallback will be removed in the future)
        --- stderr: gtest_vendor
        CMake Error: The source directory "/opt/ros/humble/share/gtest_vendor" does not appear to contain CMakeLists.txt.
        Specify --help for usage, or press the help button on the CMake GUI.
        Failed <<< gtest_vendor [0.12s, exited with code 1]
        Aborted <<< google_benchmark_vendor [0.10s]
        Aborted <<< ament_package [0.14s]
        Aborted <<< ament_cppcheck [0.11s]
        Aborted <<< ament_lint [0.13s]
        Aborted <<< ament_pycodestyle [0.12s]
        Aborted <<< osrf_pycommon [0.11s]
        Aborted <<< gtest [0.34s]

        Summary: 0 packages finished [2.78s]
        1 package failed: gtest_vendor
        7 packages aborted: ament_cppcheck ament_lint ament_package ament_pycodestyle google_benchmark_vendor gtest osrf_pycommon
        2 packages had stderr output: google_benchmark_vendor gtest_vendor
        290 packages not processed

        从报错信息来看,你在 /opt/ros/humble 目录下直接执行 colcon build 导致了错误。这是典型的操作误区,具体原因和解决方法如下:
        核心问题
        /opt/ros/humble 是 ROS 2 系统级安装目录(通过 apt 安装的二进制包存放路径),而非你的工作空间。该目录下的包是预编译好的二进制文件,不包含源代码和 CMakeLists.txt,因此无法直接用 colcon build 编译。
        正确操作步骤

        1. 退出系统目录,创建并使用自己的工作空间
          ROS 2 开发应在 用户自定义的工作空间 中进行,而非系统安装目录:
          bash

        回到用户目录

        cd ~

        创建并进入工作空间(例如 ros2_ws)

        mkdir -p ros2_ws/src
        cd ros2_ws

        仅在自己的工作空间中执行编译(此时src目录为空,会提示无包可编译,属于正常现象)

        colcon build
        2. 若需修改源码,需先下载对应包的源代码到工作空间
        如果需要修改 gtest_vendor 等包的源码,需从 GitHub 克隆源码到工作空间的 src 目录,再编译:
        bash

        进入工作空间的src目录

        cd ~/ros2_ws/src

        克隆需要修改的包(以gtest_vendor为例)

        git clone https://github.com/ros2/gtest_vendor.git -b humble # 注意切换到humble分支

        回到工作空间根目录编译

        cd ~/ros2_ws
        colcon build --packages-select gtest_vendor # 仅编译该包
        3. 理解系统目录与工作空间的区别
        /opt/ros/humble:系统级安装目录,存放通过 apt install 安装的二进制包,不可直接编译,也不建议修改(需要 root 权限,且易被系统更新覆盖)。
        用户工作空间(如 ~/ros2_ws):存放自定义代码或需要修改的源码,通过 colcon build 编译,编译产物在 install 目录,不会影响系统级安装。
        总结
        你需要 在自己的工作空间中进行编译,而非系统安装目录。若仅需使用 ROS 2 功能,无需编译系统目录下的包;若需修改源码,需将对应包的源代码克隆到工作空间后再编译。
        按上述步骤创建工作空间并正确放置源码后,colcon build 即可正常执行。
        这种错误输出自己看不懂直接发给AI比在这里快

        Q 1 条回复 最后回复 回复 引用 0
        • Q
          qic @凄凉的泪水
          最后由 编辑

          @凄凉的泪水 好的,感谢大佬👍 👍 👍

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