本页内容

为 QDoc 安装 Clang

QDoc 在解析 C++ 文件以及 \fn 命令中的函数签名时,QDoc 会使用 Clang。Clang 是LLVM 编译器基础设施项目的一部分。如果您打算从源代码构建 QDoc,则必须安装Clang 17.0或更高版本。

安装选项

Qt 提供了官方支持的预编译 LLVM/Clang 软件包,这些软件包已经过测试,并用于 Qt 的官方构建:

注意:在 Windows系统上 ,Qt 的预编译包仅支持 Release 构建。

系统包管理器

作为 Qt 预编译包的替代方案,您可以通过系统包管理器安装 Clang。QDoc 特别需要 Clang 编译器库及其 CMake 配置文件。相关依赖项包括:

  • llvm-<version> (基础架构)
  • clang-<version> (编译器和库)
  • libclang-<version>-dev (开发头文件)
  • libclang-cpp<version>-dev (C++ API 开发文件)

以下列出了在主流 Linux 发行版和 macOS 上使用包管理器的几种典型调用方式。

Linux

在大多数发行版中,LLVM 和 Clang 是独立的软件包。请确保安装包含ClangConfig.cmake 文件的(带版本号的)-dev 软件包。

  • Debian/Ubuntu:apt install libclang-dev clang libclang-cpp-dev
  • Fedora/RHEL:dnf install clang-devel
  • Arch Linux:pacman -S clang llvm

macOS

使用 Homebrew 的llvm 公式:

  • brew install llvm
  • 对于 ARM64 版 Mac:请使用以下配置:LLVM_INSTALL_DIR="/opt/homebrew/opt/llvm"
  • 对于 Intel 版 Mac:请使用以下配置LLVM_INSTALL_DIR="/usr/local/opt/llvm"

注意:Qt 的 构建系统会指示 CMake 查找ClangConfig.cmake 文件。请确保您安装的软件包提供了该文件。https://releases.llvm.org/download.html提供的预编译二进制文件无法使用,因为它们缺少 QDoc 所需的某些组件。

配置

当 Qt 的 configure 脚本无法找到 LLVM/Clang 库时,它会显示针对特定平台的安装指南以及您的系统所需的确切配置命令。

若要手动指定自定义的 LLVM 安装位置:

  • 设置LLVM_INSTALL_DIR 变量:configure LLVM_INSTALL_DIR="/path/to/llvm" FEATURE_clang=ON
  • 或在CMAKE_PREFIX_PATH 中添加:configure CMAKE_PREFIX_PATH="/path/to/llvm" FEATURE_clang=ON

安装 LLVM/Clang 库后,请务必使用FEATURE_clang=ON 重新配置,以启用 QDoc 编译。

© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.