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

M1 Mac Anaconda ROS环境下Ardupilot-Gazebo编译报错求助

问题

使用搭载M1芯片的Mac OS系统,通过Anaconda创建ROS环境,ROS安装时自动附带Gazebo,无需单独安装。已成功运行SITL并与QGroundControl自动连接,现在要连接Gazebo与SITL,安装ardupilot_gazebo插件后执行以下步骤无问题:

cd ardupilot_gazebo
mkdir build && cd build

但执行cmake .. -DCMAKE_BUILD_TYPE=RelWithDebInfo时出现错误:

CMake Error at CMakeLists.txt:19 (find_package):
  By not providing "Findgz-cmake3.cmake" in CMAKE_MODULE_PATH this project
  has asked CMake to find a package configuration file provided by
  "gz-cmake3", but CMake did not find one.

  Could not find a package configuration file provided by "gz-cmake3" with
  any of the following names:

    gz-cmake3Config.cmake
    gz-cmake3-config.cmake

  Add the installation prefix of "gz-cmake3" to CMAKE_PREFIX_PATH or set
  "gz-cmake3_DIR" to a directory containing one of the above files. If
  "gz-cmake3" provides a separate development package or SDK, be sure it has
  been installed.

在ROS环境中输入gazebo可正常启动Gazebo,但执行gz sim -v4 -r shapes.sdf提示“Invalid arguments”,怀疑是ROS附带的Gazebo导致CMake无法识别,寻求解决办法。

解决方案
  • 明确版本差异
    ROS附带的是Gazebo Classic(旧版,如Gazebo 11),而当前ardupilot_gazebo默认依赖新版Gazebo(Gazebo Sim,原Ignition Gazebo),两者命令、依赖库完全独立:

    • Gazebo Classic用gazebo命令启动
    • 新版Gazebo Sim用gz sim系列命令
  • 适配ROS自带的Gazebo Classic
    如果不想额外安装新版Gazebo,切换ardupilot_gazebo到兼容旧版的分支:

    cd ardupilot_gazebo
    git checkout gazebo-classic
    rm -rf build && mkdir build && cd build
    cmake .. -DCMAKE_BUILD_TYPE=RelWithDebInfo
    make -j4
    

    编译完成后,添加环境变量让Gazebo识别插件:

    # 临时生效,可添加到~/.zshrc或~/.bashrc永久生效
    export GAZEBO_PLUGIN_PATH=$GAZEBO_PLUGIN_PATH:/你的ardupilot_gazebo路径/build
    export GAZEBO_MODEL_PATH=$GAZEBO_MODEL_PATH:/你的ardupilot_gazebo路径/models
    
  • 安装新版Gazebo Sim解决依赖
    如果要使用新版Gazebo,通过Homebrew独立安装(避免和ROS版本冲突):

    brew install gz-sim7 gz-cmake3
    

    编译时指定新版Gazebo的配置路径,让CMake找到gz-cmake3:

    cd ardupilot_gazebo/build
    cmake .. -DCMAKE_BUILD_TYPE=RelWithDebInfo -Dgz-cmake3_DIR=$(brew --prefix gz-cmake3)/share/gz-cmake3/cmake
    make -j4
    

    启动时优先加载Homebrew的Gazebo路径,避免ROS版本干扰:

    export PATH=$(brew --prefix gz-sim7)/bin:$PATH
    gz sim -v4 -r shapes.sdf
    
  • 隔离Anaconda环境干扰
    如果Anaconda的环境变量影响系统库查找,编译前临时屏蔽:

    # 临时移除Anaconda相关路径
    export PATH=$(echo $PATH | tr ':' '\n' | grep -v anaconda | tr '\n' ':')
    export CMAKE_PREFIX_PATH=$(echo $CMAKE_PREFIX_PATH | tr ':' '\n' | grep -v anaconda | tr '\n' ':')
    

    编译完成后可重启终端恢复环境变量。

内容的提问来源于stack exchange,提问作者Halit Şen

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.18 16:13:03