0%

从源码构建 Qt

不建议从源码构建!除非你没 其他办法

构建费事费力,需要踩过很多坑才能得到一个勉强能用的版本。

参考 Building from Source ,需要 Perl / Python / MSVC ,其他章节跳过不用看

参考 Qt for Windows - Building from Source ,5 个步骤:

  1. 不需要商业许可
  2. 使用 qt-everywhere-src-5.15.15
  3. 配置环境:配置 clang 可以先跳过
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
REM Set up Microsoft Visual Studio 2017, where <arch> is amd64, x86, etc.
CALL "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Auxiliary\Build\vcvarsall.bat" amd64
SET _ROOT=D:\Users\Qt\qt-everywhere-src-5.15.15
SET PATH=%_ROOT%\qtbase\bin;%_ROOT%\gnuwin32\bin;%PATH%
SET _PERL=D:\Users\Qt\tool\strawberry-perl-5.40.0.1-64bit-portable
SET PATH=%_PERL%\perl\site\bin;%_PERL%\perl\bin;%_PERL%\c\bin;%PATH%
SET _PYTHON=D:\Users\fnie\AppData\Local\Programs\Python\Python313
SET _JOM=D:\Users\Qt\tool\jom_1_1_4
REM 构建 qdoc.exe QtDoc 时才需要 clang
SET _CLANG=D:\Users\Qt\tool\libclang\bin
SET _CMAKE=D:\Portable\cmake-3.30.5-windows-x86_64\bin
SET PATH=%_PYTHON%;%_JOM%;%_CLANG%;%_CMAKE%;%PATH%
REM clang 18.1.7 failed 版本太高,Qt5.15 识别不出来 ;
REM clang 12.0 ok ;
REM clang 11.0 ok
REM clang 10.0 build qdoc.exe ok ,构建 QtDoc 时 vc2019 报错:版本太低
:: SET LLVM_INSTALL_DIR=D:\Users\Qt\tool\libclang
REM Uncomment the below line when using a git checkout of the source repository
REM SET PATH=%_ROOT%\qtrepotools\bin;%PATH%
SET _ROOT=
SET _PERL=
SET _PYTHON=
SET _JOM=
SET _CLANG=
SET _CMAKE=
  1. 参考 Qt Configure Options ,尽可能地减少模块和特性,只保留需要的,减少构建时长
1
2
3
4
5
6
7
8
9
..\qt-everywhere-src-5.15.15\configure.bat -release -recheck-all -opensource^
-nomake examples -nomake tests ^
-skip qt3d -skip qtactiveqt -skip qtandroidextras -skip qtcharts -skip qtconnectivity -skip qtdatavis3d -skip qtdeclarative -skip qtgamepad -skip qtgraphicaleffects -skip qtimageformats -skip qtlocation -skip qtlottie -skip qtmacextras -skip qtmultimedia -skip qtnetworkauth -skip qtpurchasing -skip qtquick3d -skip qtquickcontrols -skip qtquickcontrols2 -skip qtquicktimeline -skip qtremoteobjects -skip qtscript -skip qtscxml -skip qtsensors -skip qtserialbus -skip qtserialport -skip qtspeech -skip qtsvg -skip qttranslations -skip qtvirtualkeyboard -skip qtwayland -skip qtwebchannel -skip qtwebengine -skip qtwebglplugin -skip qtwebsockets -skip qtwebview -skip qtwinextras -skip qtx11extras -skip qtxmlpatterns ^
-no-feature-assistant -no-feature-designer -no-feature-distancefieldgenerator -no-feature-kmap2qmap -no-feature-linguist -no-feature-makeqpf -no-feature-pixeltool -no-feature-qev -no-feature-qtdiag -no-feature-qtpaths -no-feature-qtplugininfo -no-feature-windeployqt

jom -j8
jom -j8 install
// 安装之后才能构建 docs
jom -j8 docs
  1. 构建 QtDoc 搁置,未成功。参考 Building Qt 5 Documentation ,Qt 提供了已经编译好的 clang 库备用,但有坑,/(ㄒoㄒ)/~~ ;参考 Installing Clang for QDoc 配置环境
  2. 官方提供 Qt Creator ,直接下载即可

libclang

构建 qdoc.exe 对 clang 版本比较挑剔;构建 QtDoc 非常耗时,暂未成功。

静态库

前述链接目录下中 libclang.lib 似乎是 静态库,不存在 bin\libclang.dll ,使用其中的包构建 qdoc.exe 报错:

libclang-release_18.1.7-based-windows-vs2019_64.7z 05-Jul-2024 11:00 461M
f0cffd0e9cff950af20efc36d42aefdb libclang-release_18.1.7-based-windows-vs2019_64.7z

libclang-release_120-based-windows-vs2019_64.7z 30-Apr-2021 10:37 306M
86c307866f629b0fb4fa1df801c99268 libclang-release_120-based-windows-vs2019_64.7z

libclang-release_110-based-windows-vs2019_64.7z 20-Oct-2020 20:57 290M
ff0a30c881691068c14fbed9239b3583c8c45c6a libclang-release_110-based-windows-vs2019_64.7z

使用 clang12.0 静态库构建 qdoc.exe 工具时报错:

使用clang12.0静态库构建qdoc工具时报错

在 [How can I get rid of the imp prefix in the linker in VC++? 中也提到:__imp_ 是动态库特有的前缀。

动态库

上一层 目录 中的 libclang.lib 是 动态库 配套的导入库,存在 bin\libclang.dll ,使用特定的版本构建 qdoc.exe 成功:

libclang-release_18.1.7-based-windows-vs2019_64.7z 12-Jun-2024 12:50 628M
ceecf8830149829d1269bf0008319c34 libclang-release_18.1.7-based-windows-vs2019_64.7z

libclang-release_120-based-windows-vs2019_64.7z 03-May-2021 11:57 364M
e6a729d347b5cedb3391a59ca695dcfe libclang-release_120-based-windows-vs2019_64.7z

libclang-release_110-based-windows-vs2019_64.7z 23-Mar-2021 10:44 342M
488375c83ea2d808d1b2e96e1ca68a8b libclang-release_110-based-windows-vs2019_64.7z

libclang-release_100-based-windows-vs2019_64.7z 18-Sep-2020 10:09 317M
MD5 Hash: 00aac61180028608e421c7a02b798b24

使用 clang10.0 动态库构建文档时报错:

使用clang10.0动态库构建文档时报错