在 Windows 10 編譯 Qt 5.5 源代碼的詳細過程 步驟詳解
以下編譯過程僅適於 Qt 5.5 及其子版本,經測試可放心使用 (意外情況除外)。
從 Qt 官網或 國內鏡像 下載源代碼。
注意: 從 Qt 官網 git 下載的源代碼可能無法使用,因為經常修改可能不穩定。
git 獲取源碼 --> cmd --> X: --> cd ./Qt --> git clone git://code.qt.io/Qt/qt5.git --> cd ./qt5 --> git checkout 5.5 --> git submodule update --init --recursive
git 更新源碼 --> cmd --> X: --> cd ./Qt/qt5 --> git remote -v --> git fetch origin --> git log -p 5.5 origin/5.5 --> git merge origin/5.5 --> git submodule update
安裝 Windows SDK 10.0.18362 (編譯 qtwebkit 時需要)
把 C:\Program Files (x86)\Windows Kits\10\bin\;C:\Program Files (x86)\Windows Kits\10\lib\;C:\Program Files (x86)\Windows Kits\10\Include\; 添加到 path 環境變量
把 C:\Program Files (x86)\Windows Kits\10\bin\10.0.18362.0\x64\;C:\Program Files (x86)\Windows Kits\10\Lib\10.0.18362.0\um\x64\; 添加到 path 環境變量
把 C:\Program Files (x86)\Windows Kits\10\Redist\D3D\x64\;C:\Program Files (x86)\Windows Kits\10\Windows Performance Toolkit\; 添加到 path 環境變量
把 C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Bin\x64\;C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Lib\x64\; 添加到 path 環境變量
在編譯 ANGLE 時需要 DirectX 11 (僅適於 Windows 7),Windows SDK 10.0.18362 帶有 DirectX 12 (通過 dxdiag 命令查看版本)。
位置 C:\Program Files (x86)\Microsoft DirectX SDK (June 2010) --> 把 C:\Program Files (x86)\Microsoft DirectX SDK (June 2010)\Utilities\bin\x64\; 添加到 path 環境變量
安裝 Visual Studio 2010 Ultimate (x86) 英文版 (非英文版編譯時, 某些字符由於存在兼容性問題可能齣錯)
位置 X:\MSVC\Microsoft Visual Studio 10.0 --> 勾選 Microsoft Visual Studio 2010 Ultimate 下 Visual C++ --> 去除其它非必要安裝項
安裝 mu_visual_studio_2010_sp1_x86_x64_dvd_651704.iso 升級包 --> 把 X:\MSVC\Microsoft Visual Studio 10.0\VC\bin\; 添加到 path 環境變量
安裝 qt-opensource-windows-x86-5.x.exe (或帶 qmake 的其它 *.EXE 二進製發行版) --> 安裝時需要填入 Qt 用戶賬號 (沒有賬號需要先申請) -->
安裝位置 X:\Qt\Qt5.x --> 成功完成後,添加以下環境變量:
把 C:\Windows;C:\Windows\System32; 和 X:\Qt\Qt5.x\5.x\msvc201x_64\bin\; 添加到 path 環境變量頭部
查看版本 --> cmd --> qmake -v
安裝 Python 2.7.9 或以上版本 (不支持 Python 3.x,編譯 qtwebkit 時需要)
位置 X:\Python27 --> 勾選 Add python.exe to Path 環境變量 --> 把 F:\Python27\;F:\Python27\Scripts\; 添加到 path 環境變量
查看版本 --> cmd --> python -v
把 C:\Perl64\bin\;C:\Perl64\lib\; 及 C:\Perl64\site\bin\;C:\Perl64\site\lib\; 添加到 path 環境變量
查看版本 --> cmd --> perl -v
下載 Rubyinstaller-2.4.2-x64.exe --> 安裝 Rubyinstaller-2.4.2-x64.exe (編譯 qtwebkit 時需要)
位置 X:\Ruby24-x64 --> 勾選 Add Ruby executables to your PATH 環境變量 --> 把 X:\Ruby24-x64\bin\;F:\Ruby24-x64\lib\; 添加到 path 環境變量
查看版本 --> cmd --> ruby -v
到 https://sourceforge.net/projects/getgnuwin32 下載 GetGnuWin32-0.6.3.exe --> 安裝位置 X:\GnuWin32 --> 把 X:\GnuWin32\bin\;X:\GnuWin32\lib\; 添加到 path 環境變量
到 https://sourceforge.net/projects/winflexbison 下載 win_flex_bison3-latest.zip --> 解壓到 X:\win_flex_bison 目錄下 --> 把 X:\win_flex_bison\; 添加到 path 環境變量 --> 若在 qt5.git 之外構建 qtbase,把 win_bison 和 win_flex 重命名為 bison 和 flex
到 https://sourceforge.net/projects/gnuwin32 下載 bison-2.4.1 --> 安裝位置 X:\GnuWin32 --> 安裝 flex-2.5.4a-1 --> 安裝 gperf-3.0.1 --> 安裝 grep-2.5.4 --> 安裝 libiconv-1.9.2-1
編譯 ANGLE qtwebkit 時需要 Bison、Flex、GPerf
若以上 GnuWin32 鏈接無法下載,請轉至 國內鏡像
注意:OpenSSL 版本不通過低也不能過高,否則無法使用。
安裝 Win64OpenSSL 1.1.0 以下版本 (OpenSSL 1.1 及之後版本,尚不兼容)
位置 X:\OpenSSL-Win64 --> 勾選 Copy OpenSSL DLLs to: The OpenSSL binaries (/bin) directory
把 X:\OpenSSL-Win64\bin\;X:\OpenSSL-Win64\lib\; 添加到 path 環境變量
下載 icu4c-58.2-Win64-MSVC2010.7z --> 解壓 icu4c-58.2-Win64-MSVC2010.7z 到 X:\icu4c
把 X:\icu4c\bin\;X:\icu4c\lib\; 添加到 path 環境變量
qtwebkit 編譯設置。
控製麵闆 --> 時間、語言和區域 --> 區域 --> 更改位置 --> 管理 --> 更改係統區域設置 --> 英語(美國)--> 確定 --> 重啓
解壓 qt-everywhere-opensource-src-5.5.0.zip 到 X:\Qt\qt-everywhere-opensource-src-5.5.0 目錄下 (注意:此硬盤分區 100GB 以上)
使用 數據比較 工具, 比對 qt-opensource-windows-x86-5.5.0.exe 安裝包自帶源碼 (查看源碼是否差異太大, 是否存在問題)
調用 Visual Studio x64 Win64 Command Prompt (2010) (如有更新環境變量, 需重啓此窗口) --> X: --> cd .\Qt\qt-everywhere-opensource-src-5.5.0
configure -confirm-license -opensource -platform win32-msvc2010 -release -mp -prefix "X:\Qt\Qt5.5.0_x64_custom\5.5\msvc2010_64" -opengl es2 -angle -icu -qt-pcre -qt-zlib -qt-freetype -qt-libpng -qt-libjpeg -qt-sql-sqlite -plugin-sql-sqlite -largefile -nomake tests -nomake examples -openssl -I X:\OpenSSL-Win64\include -L X:\OpenSSL-Win64\lib -I X:\icu4c\include -L X:\icu4c\lib64 -target xp
編譯並將結果拷貝到 X:\Qt\Qt5.5.0_x64_custom 目錄下
jom --> jom install 或 nmake --> nmake install
到 http://www.sqlite.org/download.html 下載 sqlite-amalgamation-3190300.zip 源代碼 --> 解壓到 X:\sqlite3 目錄下 --> 把 X:\Qt\Qt5.5.0\5.5\msvc2015_64\bin\; 改為 X:\Qt\Qt5.5.0_x64_custom\5.5\msvc2010_64\bin\; 添加到 path 環境變量
Visual Studio x64 Win64 Command Prompt (2010) --> X: --> cd .\Qt5.5.0\qtwebkit --> set SQLITE3SRCDIR=X:\sqlite3 --> set QTDIR=X:\Qt\Qt5.5.0_x64_custom\5.5\msvc2010_64 --> perl Tools\Scripts\build-webkit --qt --release --> perl Tools\Scripts\build-webkit --qt --makeargs=qmake --release
安裝 qtwebkit --> cd .\WebKitBuild\Release --> nmake install
測試 qtwebkit --> 把 X:\Qt\Qt5.5.0_x64_custom\5.5\msvc2010_64\lib\; 添加到 path 環境變量 --> 雙擊運行 X:\Qt5.5.0\qtwebkit\WebKitBuild\Release\bin\QtTestBrowser.exe
Qt5.5.1\qtwebkit --> flex --noline --nounistd --outfile=generated\glslang_lex.cpp src\compiler\glslang.l C:\Program Files\GnuWin32\bin\flex.EXE: unknown flag '-'. --> 把 X:\win_flex_bison\win_flex.exe 重命名成 X:\win_flex_bison\flex.exe --> 把 X:\win_flex_bison\win_bison.exe 重命名成 X:\win_flex_bison\bison.exe --> 把 X:\GnuWin32\bin\flex.exe 重命名成 X:\GnuWin32\bin\backup_flex.exe --> 把 X:\GnuWin32\bin\bison.exe 重命名成 X:\GnuWin32\bin\backup_bison.exe
Qt5.5.1\qtwebengine --> warning C4819: 該文件包含不能在當前代碼頁(936)中錶示的字符。請將該文件保存為 Unicode 格式以防止數據丟失 --> qtcreator --> 工具 --> 選項 --> 文本編輯器 --> 行為 --> UTF-8 BOM: 如果編碼是 UTF-8 則添加 --> 打開文件 --> 保存文件
相關工具或軟件,請跳轉 下載中心 。
若仍不會編譯,可聯係 客服 尋求幫助 (或關注樂數軟件相關在綫資源)。
Qt 5.5.1 在 CMD 窗口, configure -? 輸齣信息。
X:\Qt\qt-everywhere-opensource-src-5.5.1>configure -help + cd qtbase + X:\Qt\qt-everywhere-opensource-src-5.5.1\qtbase\configure.bat -top-level -help Usage: configure [options] Installation options: These are optional, but you may specify install directories. -prefix <dir> ...... The deployment directory, as seen on the target device. (default %CD%) -extprefix <dir> ... The installation directory, as seen on the host machine. (default SYSROOT/PREFIX) -hostprefix [dir] .. The installation directory for build tools running on the host machine. If [dir] is not given, the current build directory will be used. (default EXTPREFIX) You may use these to change the layout of the install. Note that all directories except -sysconfdir should be located under -prefix/-hostprefix: -bindir <dir> ...... User executables will be installed to <dir> (default PREFIX/bin) -libdir <dir> ...... Libraries will be installed to <dir> (default PREFIX/lib) -headerdir <dir> ... Headers will be installed to <dir> (default PREFIX/include) -archdatadir <dir> . Architecture-dependent data used by Qt will be installed to <dir> (default PREFIX) -libexecdir <dir> .. Program executables will be installed to <dir> (default ARCHDATADIR/bin) -plugindir <dir> ... Plugins will be installed to <dir> (default ARCHDATADIR/plugins) -importdir <dir> ... Imports for QML1 will be installed to <dir> (default ARCHDATADIR/imports) -qmldir <dir> ...... Imports for QML2 will be installed to <dir> (default ARCHDATADIR/qml) -datadir <dir> ..... Data used by Qt programs will be installed to <dir> (default PREFIX) -docdir <dir> ...... Documentation will be installed to <dir> (default DATADIR/doc) -translationdir <dir> Translations of Qt programs will be installed to <dir> (default DATADIR/translations) -examplesdir <dir> . Examples will be installed to <dir> (default PREFIX/examples) -testsdir <dir> .... Tests will be installed to <dir> (default PREFIX/tests) -hostbindir <dir> .. Host executables will be installed to <dir> (default HOSTPREFIX/bin) -hostlibdir <dir> .. Host libraries will be installed to <dir> (default HOSTPREFIX/lib) -hostdatadir <dir> . Data used by qmake will be installed to <dir> (default HOSTPREFIX) Configure options: The defaults (*) are usually acceptable. A plus (+) denotes a default value that needs to be evaluated. If the evaluation succeeds, the feature is included. Here is a short explanation of each option: -release ........... Compile and link Qt with debugging turned off. * -debug ............. Compile and link Qt with debugging turned on. + -debug-and-release . Compile and link two Qt libraries, with and without debugging turned on. -force-debug-info .. Create symbol files for release builds. -separate-debug-info Strip debug information into a separate file. -developer-build ... Compile and link Qt with Qt developer options (including auto-tests exporting) -opensource ........ Compile and link the Open-Source Edition of Qt. -commercial ........ Compile and link the Commercial Edition of Qt. -c++11 ............. Compile Qt with C++11 support enabled. -no-c++11 .......... Do not compile Qt with C++11 support enabled. -use-gold-linker ... Link using the GNU gold linker (gcc only). * -no-use-gold-linker Do not link using the GNU gold linker. -enable-new-dtags .. Use new DTAGS for RPATH (Linux only). * -disable-new-dtags . Do not use new DTAGS for RPATH. * -shared ............ Create and use shared Qt libraries. -static ............ Create and use static Qt libraries. * -static-runtime .... Statically link the C/C++ runtime library. -ltcg .............. Use Link Time Code Generation. (Release builds only) * -no-ltcg ........... Do not use Link Time Code Generation. -make <part> ....... Add part to the list of parts to be built at make time libs tools examples -nomake <part> ..... Exclude part from the list of parts to be built. -skip <module> ..... Exclude an entire module from the build. -no-compile-examples Install only the sources of examples. -no-widgets ........ Disable Qt Widgets module. -no-gui ............ Disable Qt GUI module. -no-accessibility .. Disable accessibility support. ................... Disabling accessibility is not recommended, as it will break QStyle and may break other internal parts of Qt. With this switch you create a source incompatible version of Qt, which is unsupported. * -accessibility ..... Enable accessibility support. -no-sql-<driver> ... Disable SQL <driver> entirely, by default none are turned on. -qt-sql-<driver> ... Enable a SQL <driver> in the Qt Library. -plugin-sql-<driver> Enable SQL <driver> as a plugin to be linked to at run time. Available values for <driver>: mysql psql oci odbc tds db2 + sqlite sqlite2 ibase (drivers marked with a '+' have been detected as available on this system) -system-sqlite ..... Use sqlite from the operating system. -no-opengl ......... Do not support OpenGL. -opengl <api> ...... Enable OpenGL support with specified API version. Available values for <api>: desktop - Enable support for Desktop OpenGL dynamic - Enable support for dynamically loaded OpenGL (either desktop or ES) * es2 - Enable support for OpenGL ES 2.0 * -no-openvg ......... Disables OpenVG functionality. -openvg ............ Enables OpenVG functionality. -force-asserts ..... Activate asserts in release mode. -platform <spec> ... The operating system and compiler you are building on. (default %QMAKESPEC%) -xplatform <spec> .. The operating system and compiler you are cross compiling to. See the README file for a list of supported operating systems and compilers. -target ............ Set target OS version. Currently the only valid value is 'xp' for targeting Windows XP. MSVC >= 2012 targets Windows Vista by default. -sysroot <dir> ..... Sets <dir> as the target compiler's and qmake's sysroot and also sets pkg-config paths. -no-gcc-sysroot .... When using -sysroot, it disables the passing of --sysroot to the compiler. -qconfig <local> ... Use src/corelib/global/qconfig-<local>.h rather than the default 'full'. * -no-nis ............ Do not compile NIS support. -nis ............... Compile NIS support. -no-iconv .......... Do not enable support for iconv(3). + -iconv ............. Enable support for iconv(3). + -sun-iconv ......... Enable support for iconv(3) using sun-iconv. + -gnu-iconv ......... Enable support for iconv(3) using gnu-libiconv. -no-evdev .......... Do not enable support for evdev. + -evdev ............. Enable support for evdev. -no-mtdev .......... Do not enable support for mtdev. + -mtdev ............. Enable support for mtdev. + -inotify ........... Explicitly enable Qt inotify(7) support. -no-inotify ........ Explicitly disable Qt inotify(7) support. + -eventfd ........... Enable eventfd(7) support in the UNIX event loop. -no-eventfd ........ Disable eventfd(7) support in the UNIX event loop. * -largefile ......... Enables Qt to access files larger than 4 GB. -fontconfig ........ Build with FontConfig support. * -no-fontconfig ..... Do not build with FontConfig support. -posix-ipc ......... Enable POSIX IPC. -glib .............. Compile Glib support. -sysconfdir <dir> .. Settings used by Qt programs will be looked for in <dir>. -system-proxies .... Use system network proxies by default. * -no-system-proxies . Do not use system network proxies by default. + -warnings-are-errors Make warnings be treated as errors. -no-warnings-are-errors Make warnings be treated normally. -qtnamespace <name> Wraps all Qt library code in 'namespace name {...}'. -qtlibinfix <infix> Renames all Qt* libs to Qt*<infix>. -D <define> ........ Add an explicit define to the preprocessor. -I <includepath> ... Add an explicit include path. -L <librarypath> ... Add an explicit library path. -l <libraryname> ... Add an explicit library name, residing in a librarypath. -help, -h, -? ...... Display this information. Third Party Libraries: -qt-zlib ........... Use the zlib bundled with Qt. + -system-zlib ....... Use zlib from the operating system. See http://www.gzip.org/zlib -qt-pcre ........... Use the PCRE library bundled with Qt. + -system-pcre ....... Use the PCRE library from the operating system. See http://pcre.org/ -icu ............... Use the ICU library. * -no-icu ............ Do not use the ICU library. See http://site.icu-project.org/ -no-gif ............ Do not compile GIF reading support. -no-libpng ......... Do not compile PNG support. -qt-libpng ......... Use the libpng bundled with Qt. + -system-libpng ..... Use libpng from the operating system. See http://www.libpng.org/pub/png -no-libjpeg ........ Do not compile JPEG support. -qt-libjpeg ........ Use the libjpeg bundled with Qt. + -system-libjpeg .... Use libjpeg from the operating system. See http://www.ijg.org -no-freetype ....... Do not compile in Freetype2 support. * -qt-freetype ....... Use the libfreetype bundled with Qt. -system-freetype ... Use the libfreetype provided by the system. -no-harfbuzz ....... Do not compile in HarfBuzz-NG support. * -qt-harfbuzz ....... Use HarfBuzz-NG bundled with Qt to do text shaping. It can still be disabled by setting the QT_HARFBUZZ environment variable to "old". -system-harfbuzz ... Use HarfBuzz-NG from the operating system to do text shaping. It can still be disabled by setting the QT_HARFBUZZ environment variable to "old". See http://www.harfbuzz.org + -angle ............. Use the ANGLE implementation of OpenGL ES 2.0. -no-angle .......... Do not use ANGLE. See http://code.google.com/p/angleproject/ Qt for Windows only: -no-incredibuild-xge Do not add IncrediBuild XGE distribution commands to custom build steps. + -incredibuild-xge .. Add IncrediBuild XGE distribution commands to custom build steps. This will distribute MOC and UIC steps, and other custom buildsteps which are added to the INCREDIBUILD_XGE variable. (The IncrediBuild distribution commands are only added to Visual Studio projects) * -no-plugin-manifests Do not embed manifests in plugins. -plugin-manifests .. Embed manifests in plugins. -no-qmake .......... Do not compile qmake. * -qmake ............. Compile qmake. -qreal [double|float] typedef qreal to the specified type. The default is double. Note that changing this flag affects binary compatibility. -no-rtti ........... Do not compile runtime type information. * -rtti .............. Compile runtime type information. -no-strip .......... Do not strip libraries and executables of debug info when installing. * -strip ............. Strip libraries and executables of debug info when installing. -no-sse2 ........... Do not compile with use of SSE2 instructions. + -sse2 .............. Compile with use of SSE2 instructions. -no-sse3 ........... Do not compile with use of SSE3 instructions. + -sse3 .............. Compile with use of SSE3 instructions. -no-ssse3 .......... Do not compile with use of SSSE3 instructions. + -ssse3 ............. Compile with use of SSSE3 instructions. -no-sse4.1 ......... Do not compile with use of SSE4.1 instructions. + -sse4.1 ............ Compile with use of SSE4.1 instructions. -no-sse4.2 ......... Do not compile with use of SSE4.2 instructions. + -sse4.2 ............ Compile with use of SSE4.2 instructions. -no-avx ............ Do not compile with use of AVX instructions. + -avx ............... Compile with use of AVX instructions. -no-avx2 ........... Do not compile with use of AVX2 instructions. + -avx2 .............. Compile with use of AVX2 instructions. -no-ssl ............ Do not compile support for SSL. + -ssl ............... Enable run-time SSL support. -no-openssl ........ Do not compile support for OpenSSL. + -openssl ........... Enable run-time OpenSSL support. -openssl-linked .... Enable linked OpenSSL support. -no-libproxy ....... Do not compile in libproxy support. + -libproxy .......... Compile in libproxy support (for cross compilation targets). -no-dbus ........... Do not compile in D-Bus support. + -dbus .............. Compile in D-Bus support and load libdbus-1 dynamically. -dbus-linked ....... Compile in D-Bus support and link to libdbus-1. -no-audio-backend .. Do not compile in the platform audio backend into Qt Multimedia. + -audio-backend ..... Compile in the platform audio backend into Qt Multimedia. -no-wmf-backend .... Do not compile in the windows media foundation backend into Qt Multimedia. + -wmf-backend ....... Compile in the windows media foundation backend into Qt Multimedia. -no-qml-debug ...... Do not build the in-process QML debugging support. * -qml-debug ......... Build the in-process QML debugging support. * -no-directwrite .... Do not build support for DirectWrite font rendering. -directwrite ....... Build support for DirectWrite font rendering (requires DirectWrite availability on target systems, e.g. Windows Vista with Platform Update, Windows 7, etc.) * -no-direct2d ....... Do not build the Direct2D platform plugin. -direct2d .......... Build the Direct2D platform plugin (experimental, requires Direct2D availability on target systems, e.g. Windows 7 with Platform Update, Windows 8, etc.) -no-style-<style> .. Disable <style> entirely. -qt-style-<style> .. Enable <style> in the Qt Library. Available styles: * windows + windowsxp + windowsvista * fusion windowsce windowsmobile -no-native-gestures Do not use native gestures on Windows 7. * -native-gestures ... Use native gestures on Windows 7. * -no-mp ............. Do not use multiple processors for compiling with MSVC -mp ................ Use multiple processors for compiling with MSVC (-MP). -loadconfig <config> Run configure with the parameters from file configure_ <config>.cache. -saveconfig <config> Run configure and save the parameters in file configure_<config>.cache. -redo .............. Run configure with the same parameters as last time. Qt for Windows CE only: * -no-crt ............ Do not add the C runtime to default deployment rules. -qt-crt ............ Qt identifies C runtime during project generation. -crt <path> ........ Specify path to C runtime used for project generation. -no-cetest ......... Do not compile Windows CE remote test application. + -cetest ............ Compile Windows CE remote test application. -signature <file> .. Use <file> for signing the target project. X:\Qt\qt-everywhere-opensource-src-5.5.1>
版權聲明: 本文為獨傢原創稿件,版權歸 樂數軟件 ,未經許可不得轉載。