为 QDoc 安装 Clang

QDoc 在解析 C++ 文件以及\fn命令中的函数签名时使用了 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/Ubuntuapt install libclang-dev clang libclang-cpp-dev
  • Fedora/RHELdnf install clang-devel
  • Arch Linux pacman -S clang llvm

macOS

使用 Homebrew 的llvm 公式

  • brew install llvm
  • 对于 ARM64 Mac:使用LLVM_INSTALL_DIR="/opt/homebrew/opt/llvm"
  • 英特尔 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_PATHconfigure CMAKE_PREFIX_PATH="/path/to/llvm" FEATURE_clang=ON

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

© 2025 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.