Qt5.15.2 msvc靜態編譯記錄


0 參考

QT最新版5.14在WINDOWS環境靜態編譯安裝和部署的完整過程 VS 2019-QT STATIC LINK BUILD WINDOWS 32 BIT/64 BIT
MSVC 靜態編譯 Qt 5
Win7下靜態編譯QT5.12源碼
Building Qt 5 from Git

1 獲取源碼

試過通過官網的MaintenanceTool,還有git獲取的源碼,編譯時總是有報錯,最后試着從清華源獲取源碼,成了。
https://mirrors.tuna.tsinghua.edu.cn/qt/archive/qt/5.15/5.15.2/single/qt-everywhere-src-5.15.2.zip

2 編譯工具

源碼路徑下的README文件中有編譯方式的說明,其中列出來Windows下編譯所需工具

   Windows:
   --------

     Open a command prompt.
     Ensure that the following tools can be found in the path:
     * Supported compiler (Visual Studio 2012 or later,
        MinGW-builds gcc 4.9 or later)
     * Perl version 5.12 or later   [http://www.activestate.com/activeperl/]
     * Python version 2.7 or later  [http://www.activestate.com/activepython/]
     * Ruby version 1.9.3 or later  [http://rubyinstaller.org/]

python需要python2,python3不行,下面是我的版本

This is perl 5, version 32, subversion 1 (v5.32.1) built for MSWin32-x64-multi-thread
Python 2.7.18
ruby 2.7.3p183 (2021-04-05 revision 6847ee089d) [x64-mingw32] (strawberry-perl-5.32.1.1-64bit)

如果安裝有問題或者環境變量有問題之后configure配置時會報warning

3 修改\qt-everywhere-src-5.15.2\qtbase\mkspecs\common\msvc-desktop.conf

將文件中-MD 全改為 -MT(3處)

4 configure配置

打開x64 Native Tools Command Prompt for VS 2019(打算編譯成64位就打開x64,32位打開x86),
cd 到源文件文件夾

configure.bat -prefix S:\Qt\5.15.2\Qt5.15.2-static -confirm-license -opensource -debug-and-release -static -static-runtime -angle -combined-angle-lib -no-feature-d3d12 -platform win32-msvc -mp -nomake tests -nomake examples -nomake tools -skip qtwebengine -skip qtwebview

參數的具體含義參考博客里說的非常詳細,這里就不貼了,請自己根據需求調整。
configure -h指令可以查看允許的參數與簡介

完成時會顯示結果(warning,如果有的話)與下一步指示
Qt is now configured for building. Just run 'nmake'.
Once everything is built, you must run 'nmake install'.
Qt will be installed into '設定的編譯結果路徑'.

5 編譯

繼續運行nmake,需要等待比較長的時間。
當nmake完成時,繼續運行nmake install,完成時就結束了。

6 添加到Qt Creator

我是用MaintenanceTool下載的Qt Creator
https://www1.qt.io/download-open-source-access/

工具-選項-Kits-Qt Versions
點擊添加,找的編譯結果目錄bin中的qmake.exe,
會給一個找不到qmlscene.exe的警告,我的解決方案是去別的庫(可以用MaintenanceTool下載)bin目錄下復制個過來。

工具-選項-Kits-kits
設置好 名稱,Compiler(64還是32由編譯方式決定),Qt Version(上一步剛剛添加的版本)

簡單寫個程序測試下


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM