Skip to content

从源码开始并构建

本主题说明如何获取 QGroundControl 源代码并在本机或在 Vagrant 环境中构建它。 本主题还提供其他可选功能信息及特定于操作系统的功能信息。 本主题还提供其他可选功能信息及特定于操作系统的功能信息。

每日构建

如果您只是想测试 (而不是调试) 最近生成的 QGroundControl ,那么请使用Daily build。 官方提供了适用于所有平台的版本。 官方提供了适用于所有平台的版本。

源代码

QGroundControl 的源代码保存在GitHub 上:https://github.com/mavlink/qgroundcontrol。 它采用 Apache 2.0 和 GPLv3 双重授权

要获取源文件, 请执行以下操作:

  1. 克隆存储库 (或您的分叉), 包括子模块:

    sh
    git clone --recursive -j8 https://github.com/mavlink/qgroundcontrol.git
  2. 2.更新子模块(每次拉新源代码时都这样做):

    sh
    git submodule update --recursive

TIP

提示:不能使用Github以zip形式下载源文件,因为zip压缩包中不包含相应的子模块源代码。 你必须使用git工具! 你必须使用git工具!

构建QGroundControl开发环境

使用容器

我们支持使用存储库源代码树上的容器进行 Linux 构建,这可以帮助您开发和部署 QGC 应用程序,而无需在本地环境中安装任何要求。

容器指南

原生构建

QGroundControl 支持macos、linux、windows 和 Android 平台的构建。 理论上可以为iOS创建一个 QGC 版本,但不再支持作为标准构建。 QGroundControl 使用 Qt作为其跨平台支持库。

所需的 Qt 版本为 6.10.0 (必须无误)

WARNING

请勿使用任何其他版本的 Qt! QGC 已通过指定 Qt 版本(6.10.0)的全面测试。 其它的 Qt 版本很可能会注入影响稳定和安全的 bug (即使QGC 编译通过)。

更多信息请看: Qt 6 支持平台列表

安装Qt

必须像下面描述的那样安装Qt ,而不是使用预构建的软件包,例如Linux发行版。

如何安装Qt:

  1. 下载并运行Qt Online Installer

    • Ubuntu:
      • 使用以下命令将下载的文件设置为可执行文件:chmod + x
      • 您可能还需要安装 libxcb-cursor0
  2. 在 _Installation 文件夹页面选择"自定义安装"

  3. 选择组件 页面:

    • 如果您没有看到 6.10.0_ 列出_Qt选中 Archive 复选框并单击 Filter
  • 在 Qt -> Qt 6.10.0 下选择:
    • Windows: MSVC 2022 arch - 其中 “arch” 指的是您机器的架构
    • Mac:桌面
    • Linux: gcc 64-bit 桌面
    • Android: Android
  • 选择所有 Additional Libraries
  • 取消选择 QT Design Studio
  1. 安装附加软件包(特殊平台)

    • Ubuntu: sudo bash ./qgroundcontrol/tools/setup/install-dependencies-debian.sh
    • Fedora: sudo dnf install speech-dispatcher SDL2-devel SDL2 systemd-devel patchelf
    • Arch Linux: pacman -Sy speech-dispatcher patchelf
    • Mac sh qgroundcontrol/tools/setup/install-dependencies-osx.sh
    • Windows qgroundcontrol/tools/setup/install-depedencies-windows.ps1
    • Android Installing dependencies for android is quite involved. You are better off using Qt documentation for android setup instructions. Search for "Qt 6.10 android" on the internet to find the correct "Gettting Started with Qt for Android" page. Read it full and carefully! An example of what you are looking for is here.
  2. 安装可选/特定操作功能

    INFO

    依赖操作系统和用户安装的库的可选功能在下面链接/描述。 这些功能可以被强制启用/禁用,为qmake指定额外的值。

安装 Visual Studio (仅限Windows)

安装 Visual Studio 2022 Community Edition

进行安装时,选择 使用 C++ 进行桌面开发

Visual Studio 2019 - 选择基于 C++ 的桌面开发环境

INFO

Visual Studio 仅用于获取编译器。 构建 QGroundControl 可直接按以下概述,使用 Qt Creatorcmake 完成。

使用 Qt Creator {#qt-creator} 进行构建

  1. 启动 Qt Creator,选择 Open Project 并选择 CMakeLists.txt 文件。

  2. Configure Project 页面上,它应该默认您刚刚使用上面的说明安装的 Qt 版本。 如果不从列表中选择该套件,然后点击 Configure Project

  3. 使用"hammer" (或"play") 图标或菜单构建:

    QtCreator Build Button

在CLI(命令行界面)使用 CMake {#cmake} 进行构建

构建默认的 QGC 示例命令并在此后运行它:

  1. 请确保您克隆了仓库并先更新子模块,见上文 源代码 章节并切换到仓库文件夹:

    sh
    cd qgroundcontrol
  2. 配置:

    sh
    ~/Qt/{{ $frontmatter.qt_version }}/gcc_64/bin/qt-cmake -B build -G Ninja -DCMAKE_BUILD_TYPE=Debug

    修改 qt-cmake 的目录,使其与你安装 Qt 的位置以及你想要使用的工具包相匹配。

    Mac: To Sign/Notarize/Staple the QGC app bundle, add -DQGC_MACOS_SIGN_WITH_IDENTITY=ON to the configure command line. During the install phase the following environment variables will need to be available:

    • QGC_MACOS_SIGNING_IDENTITY - Signing identity for your Developer ID certificate which must be in the keychain
    • QGC_MACOS_NOTARIZATION_USERNAME - Username for your Apple Developer Account
    • QGC_MACOS_NOTARIZATION_PASSWORD - App specific password for Notarization from your Apple Developer Account
    • QGC_MACOS_NOTARIZATION_TEAM_ID - Apple Developer Account Team ID
  3. 构建

    sh
    cmake --build build --config Debug
  4. Run the QGroundcontrol binary that was just built: ./staging/QGroundControl

    sh
    ./build/Debug/QGroundControl

Vagrant

Vagrant 可以在 Linux 虚拟机内构建和运行 QGroundControl (如果兼容,也可以在主机机上运行)。

  1. 下载安装 Vagrant
  2. QGroundControl 仓库的根目录运行 vagrant up
  3. 若要使用图形环境,请运行 vagrant reload

所有支持的操作系统的额外构建备注

  • 并行构建: 对于非Windows构建,您可以使用 "-j#" 选项来运行并行构建。
  • **如果你在运行 QGroundControll**时遇到此错误: /usr/lib/x86_64-linux-gnu/libstdc++.so.6: version 'GLIBCXX_3.4.20' not found.,你需要更新到最新的 gcc ,或者通过使用 sudo apt-get install libstdc++6 安装最新的 libstdc++.6
  • 单元测试: 若要运行 单元测试,使用 QGC_UNITEST_BUILD 定义在 debug 模式下构建,然后复制 deposition / qgroundcontrol-start。 运行测试前,将 deploy/qgroundcontrol-start.sh` 脚本复制到debug目录中。

构建 QGC 安装文件

作为正常构建过程的一部分,您还可以为 QGroundControl 创建安装文件。

sh
cmake --install . --config Release