編譯 Qt 5.6(使QtWebEngine支持XP)

說明

qt 5.6的編譯進行了數十遍,才得出本文的可行方案,之因此花了這麼多的時間,主要是qt引入了QtWebEngine模塊後,致使編譯難度直線上升,並且又有一些中國特點的問題(如360安全衛士)致使,但願本文能夠爲你們節省更多的時間html

  • 爲何要本身編?
    • 由於qt的預編譯發行包中,QtWebEngine模塊的QtWebEngineProcess.exe不能在xp下運行,是由於他們編譯的時候沒用支持xp的工具集致使的

源碼下載

  • Qt git地址:git://code.qt.io/qt/qt5.git
  • 推薦用 SourceTree 客戶端來克隆源碼

準備工做

  • 系統 Windows 7 或者 Windows 10
  • 編譯器 Visual Studio 2013 Update 5 或者 Visual Studio 2015 Update 1
  • 本文在如下4種狀況下都編譯經過
    • Windows 7 + Visual Studio 2013 Update 5
    • Windows 7 + Visual Studio 2015 Update 1
    • Windows 10 + Visual Studio 2013 Update 5
    • Windows 10 + Visual Studio 2015 Update 1
  • 安裝Git,編譯過程可能會啓動 git.exe
  • 安裝ActivePerl
  • 安裝Python
  • 編譯ICU庫
  • 編譯openssl
  • 編譯webkit須要的環境
  • 最重要的準備工做
    • 保持編譯過程當中聯網
    • 關閉360等安全衛士,殺毒軟件,編譯過程當中360會彈框攔截
    • 將系統的區域改爲 英語(美國),不然編譯QtWebEngine會失敗,如圖所示

可能遇到的編譯錯誤

  • 使用 vs2013 編譯的時候,有可能會遇到如下錯誤python

    1
    Error 2 error C2440: 'default argument' : cannot convert from 'const wchar_t [1]' to 'const BSTR' (src\GAudioOutput.cc) C:\Program Files (x86)\Windows Kits\8.1\Include\um\sapi.h 16917 1 qgroundcontrol

    遇到這個問題,須要修改 qtbase\mkspecs\common\msvc-base.conf 文件,將下面這段刪除,如圖
    linux

  • 使用 VS2015 Update2/Update3 編譯時遇到如下錯誤git

    1
    2
    ...\skedge.cpp(231): error C2220: warning treated as error - no 'object' file generated
    ...\skedge.cpp(231): warning C4334: '<<': result of 32-bit shift implicitly converted to 64 bits (was 64-bit shift intended?)

    解決辦法:使用5.6.1或者5.7.0版本的qtweb

    參考連接:QtWebEngine does not build with VS2015 SP2sql

編譯

  • 新建一個 environment.bat,用來執行環境變量的設置,代碼以下:api

    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
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    @echo off

    rem 設置vs安裝路徑
    set MSVC_PATH=C:\Program Files (x86)\Microsoft Visual Studio 14.0

    rem 設置icu源碼路徑,在編譯icu時用到,編譯qt用不到源碼
    set ICU_SRC_PATH=C:\Users\king\Documents\Workspace\Qt\build\icu-source\source

    rem 設置icu編譯安裝的路徑,在編譯icu時用到,編譯qt用不到這個格式的路徑,注意安裝路徑格式,是linux風格
    set ICU_INSTALL_PATH=/cygdrive/C/Users/king/Documents/Workspace/Qt/build/icu

    rem 設置CYG依賴,在編譯icu時用到,編譯qt用不到
    set CYG_WIN_PATH=C:\Users\king\Documents\dev\cygwin64\bin

    rem 設置ICU編譯安裝的路徑,編譯Qt會用到,注意格式,是Windows風格
    set ICU_INSTALL_PATH_WIN=C:\Users\king\Documents\Workspace\Qt\build\icu

    rem 設置openssl源碼路徑,在編譯openssl時用到,編譯qt用不到源碼
    set OPENSSL_SRC_PATH=C:\Users\king\Documents\Workspace\Qt\build\openssl-1.0.1p

    rem 設置openssl的最終安裝路徑,編譯qt時會用到
    set OPENSSL_INSTALL_PATH=C:\Users\king\Documents\Workspace\Qt\build\openssl

    rem 設置編譯Qt的編譯器配置文件名
    set QMAKESPEC=win32-msvc2015

    rem 設置qt的源碼路徑
    set QT5_SRC_PATH=C:\Users\king\Documents\Workspace\Qt\qt5

    rem 設置qt編譯後的安裝路徑
    set QT5_INSTALL_PATH=C:\Users\king\Documents\Workspace\Qt\qt_5.6.0

    rem 設置git安裝路徑
    set GIT_PATH=C:\Program Files\Git

    rem 設置Perl的bin路徑
    set PERL_PATH=C:\Users\king\Documents\dev\Perl\bin

    rem 設置python安裝路徑
    set PYTHON_PATH=C:\Program Files (x86)\Python27

    rem qtwebkit依賴環境
    set WIN_FLEX_BISION_PATH=D:\Dev\win_flex_bison-latest
    set SQLITE3SRCDIR=D:\Dev\sqlite-amalgamation-3110100
    set RUBY_PATH=D:\Dev\Ruby22\bin

    rem 執行MSVC環境設置
    call "%MSVC_PATH%\VC\vcvarsall.bat" x86
  • 新建一個 build_qt.bat,用來執行qt的編譯,代碼以下安全

    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
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    @echo off

    rem 調用前一個bat,執行環境變量的設置
    call environment.bat

    rem 將qt相關的路徑加入path變量,爲何qtbase\lib也加進去,由於編譯過程當中會執行qt本身編出來的exe,會依賴qt相關的dll,因此也加進去,git路徑也加進來,保證編譯過程當中能夠找到git.exe
    set PATH=%QT5_SRC_PATH%\qtbase\bin;%QT5_SRC_PATH%\qtbase\lib;%QT5_SRC_PATH%\gnuwin32\bin;%GIT_PATH%\bin;%PATH%

    rem 將qtrepotools\bin路徑加入path環境變量
    set PATH=%QT5_SRC_PATH%\qtrepotools\bin;%PATH%

    rem 將perl,python加入path
    set PATH=%PATH%;%PERL_PATH%;%PYTHON_PATH%

    rem 設置icu和openssl庫的引用路徑
    set LIB=%LIB%;%ICU_INSTALL_PATH_WIN%\lib;%OPENSSL_INSTALL_PATH%\lib

    rem 設置icu和openssl庫的頭文件引用路徑
    set INCLUDE=%INCLUDE%;%ICU_INSTALL_PATH_WIN%\include;%OPENSSL_INSTALL_PATH%\include

    rem 將icu和openssl的bin目錄加入PATH環境變量,icu的lib路徑也加入PATH,是由於編譯過程當中運行的一些exe依賴icu庫的dll
    set PATH=%PATH%;%ICU_INSTALL_PATH_WIN%\bin;%OPENSSL_INSTALL_PATH%\bin;%ICU_INSTALL_PATH_WIN%\lib

    rem 進入qt源碼目錄
    cd /D %QT5_SRC_PATH%

    rem 配置qt,-target xp是支持xp系統,否則編出來的exe在xp下不能運行,好比QtWebEngineProcess.exe
    rem 可選參數 -force-debug-info:release版本也生成PDB文件
    call %QT5_SRC_PATH%\configure -prefix %QT5_INSTALL_PATH% -debug-and-release -opensource -confirm-license -opengl dynamic -mp -icu -openssl -nomake examples -nomake tests -target xp -skip qtwebkit -no-directwrite

    rem 執行編譯
    nmake

    rem 執行安裝
    nmake install

    rem 複製openssl和icu到qt安裝目錄中
    xcopy /y /k "%ICU_INSTALL_PATH_WIN%\lib\icudt56.dll" "%QT5_INSTALL_PATH%\bin\"
    xcopy /y /k "%ICU_INSTALL_PATH_WIN%\lib\icuin56.dll" "%QT5_INSTALL_PATH%\bin\"
    xcopy /y /k "%ICU_INSTALL_PATH_WIN%\lib\icuuc56.dll" "%QT5_INSTALL_PATH%\bin\"
    xcopy /y /k "%ICU_INSTALL_PATH_WIN%\lib\icudt.lib" "%QT5_INSTALL_PATH%\lib\"
    xcopy /y /k "%ICU_INSTALL_PATH_WIN%\lib\icuin.lib" "%QT5_INSTALL_PATH%\lib\"
    xcopy /y /k "%ICU_INSTALL_PATH_WIN%\lib\icuuc.lib" "%QT5_INSTALL_PATH%\lib\"

    xcopy /y /k "%OPENSSL_INSTALL_PATH%\bin\libeay32.dll" "%QT5_INSTALL_PATH%\bin\"
    xcopy /y /k "%OPENSSL_INSTALL_PATH%\bin\ssleay32.dll" "%QT5_INSTALL_PATH%\bin\"
    xcopy /y /k "%OPENSSL_INSTALL_PATH%\lib\libeay32.lib" "%QT5_INSTALL_PATH%\lib\"
    xcopy /y /k "%OPENSSL_INSTALL_PATH%\lib\ssleay32.lib" "%QT5_INSTALL_PATH%\lib\"

    pause
  • 雙擊執行 build_qt.bat,整個編譯過程可能須要四、5個小時,若是按照本文從頭一步一步下來,應該能夠一遍就編成功ruby

  • 新建一個 build_qtwebkit.bat,用來執行qtwebkit的編譯,代碼以下工具

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    @echo off

    call environment.bat

    set LIB=%LIB%;%ICU_INSTALL_PATH_WIN%\lib;%OPENSSL_INSTALL_PATH%\lib;%QT5_INSTALL_PATH%\lib
    set INCLUDE=%INCLUDE%;%ICU_INSTALL_PATH_WIN%\include;%OPENSSL_INSTALL_PATH%\include;%QT5_INSTALL_PATH%\include
    set PATH=%QT5_INSTALL_PATH%\bin;%WIN_FLEX_BISION_PATH%;%ICU_INSTALL_PATH_WIN%\bin;%OPENSSL_INSTALL_PATH%\bin;%ICU_INSTALL_PATH_WIN%\lib;%QT5_SRC_PATH%\gnuwin32\bin;%PERL_PATH%;%PYTHON_PATH%;%RUBY_PATH%;%PATH%

    cd /D %QT5_SRC_PATH%

    %PERL_PATH%\perl %QT5_SRC_PATH%\qtwebkit\Tools\Scripts\build-webkit --qt

    pause
  • 若是要從新編譯,須要清除以前編譯的臨時文件,能夠新建一個 clean_qt.bat 來執行清理工做,代碼以下

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    @echo off

    rem 調用前一個bat,執行環境變量的設置
    call environment.bat

    rem 將qt相關的路徑加入path變量,爲何qtbase\lib也加進去,由於編譯過程當中會執行qt本身編出來的exe,會依賴qt相關的dll,因此也加進去,git路徑也加進來,保證編譯過程當中能夠找到git.exe
    set PATH=%QT5_SRC_PATH%\qtbase\bin;%QT5_SRC_PATH%\qtbase\lib;%QT5_SRC_PATH%\gnuwin32\bin;%GIT_PATH%\bin;%PATH%

    rem 將qtrepotools\bin路徑加入path環境變量
    set PATH=%QT5_SRC_PATH%\qtrepotools\bin;%PATH%

    rem 將perl,python加入path
    set PATH=%PATH%;%PERL_PATH%;%PYTHON_PATH%

    rem 進入qt源碼目錄
    cd /D %QT5_SRC_PATH%

    rem 下面這句是用來清除全部的編譯臨時文件,有須要時再打開註釋,好比想從頭開始從新編譯
    git submodule foreach --recursive "git clean -dfx"

http://wangjie.rocks/2015/12/28/compile-qt/

相關文章
相關標籤/搜索