在 Windows 7 编译 Qt 4.8 源代码的详细过程 步骤详解


以下编译过程仅适于 Qt 4.8 及其子版本,经测试可放心使用 (意外情况除外)。

获取源码


从 Qt 官网或 国内镜像 下载源代码。

注意: 从 Qt 官网 git 下载的源代码可能无法使用,因为经常修改可能不稳定。

安装 Windows SDK


安装 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 环境变量

安装 Windows DirectX SDK


安装 DXSDK_Jun10_9.29.1962.exe

在编译 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


安装 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 环境变量

安装 qmake


安装 qt-opensource-windows-x86-vs2008-4.8.7.exe (或带 qmake 的其它 *.EXE 二进制发行版),位置 X:\Qt\Qt4.8.7

把 C:\Windows;C:\Windows\System32; 和 X:\Qt\Qt4.8.7\4.8\msvc2008\bin\ 添加到 path 环境变量头部

查看版本 --> cmd --> qmake -v

安装 Python 2.7


安装 Python 2.7.9 或以上版本 (不支持 Python 3.x,编译 qtwebkit 时需要)

位置 X:\Python27 --> 勾选 Add python.exe to Path 环境变量 --> 把 F:\Python27\;F:\Python27\Scripts\; 添加到 path 环境变量

查看版本 --> cmd --> python -v

安装 ActivePerl


安装 ActivePerl 5.22 或以上版本

把 C:\Perl64\bin\;C:\Perl64\lib\; 及 C:\Perl64\site\bin\;C:\Perl64\site\lib\; 添加到 path 环境变量

查看版本 --> cmd --> perl -v

安装 Ruby


下载 Rubyinstaller-2.3.3-x64.exe --> 安装 Rubyinstaller-2.3.3-x64.exe (编译 qtwebkit 时需要)

位置 X:\Ruby23-x64 --> 勾选 Add Ruby executables to your PATH 环境变量 --> 把 X:\Ruby23-x64\bin\;F:\Ruby23-x64\lib\; 添加到 path 环境变量

查看版本 --> cmd --> ruby -v

安装 GnuWin32


到 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 链接无法下载,请转至 国内镜像

安装 Win64OpenSSL


注意: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 环境变量

区域设置


qtwebkit 编译设置。

控制面板 --> 时间、语言和区域 --> 区域 --> 更改位置 --> 管理 --> 更改系统区域设置 --> 英语(美国)--> 确定 --> 重启

比对源码


解压 qt-everywhere-opensource-src-4.8.7.zip 到 X:\Qt\qt-everywhere-opensource-src-4.8.7 目录下

使用 数据比较 工具, 比对 qt-opensource-windows-x86-vs2010-4.8.7.exe 安装包自带源码 (查看源码是否差异太大, 是否存在问题)

编译 Qt4.8


调用 Visual Studio x64 Win64 Command Prompt (2010) (如有更新环境变量, 需重启此窗口) --> X: --> cd .\Qt\qt-everywhere-opensource-src-4.8.7

configure -confirm-license -opensource -platform win32-msvc2010 -release -mp -prefix "X:\Qt\Qt4.8.7_x64_custom\4.8\msvc2010_64" -opengl desktop -qt-zlib -qt-libpng -qt-libmng -qt-libtiff -qt-libjpeg -qt-sql-sqlite -plugin-sql-sqlite -largefile -no-qt3support -nomake tests -nomake examples -no-webkit -openssl -I X:\OpenSSL-Win64\include -L X:\OpenSSL-Win64\lib

编译并将结果拷贝到 X:\Qt\Qt4.8.7_x64_custom 目录下

jom --> jom install 或 nmake --> nmake install

编译 qtwebkit


把 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

到 http://www.sqlite.org/download.html 下载 sqlite-amalgamation-3190300.zip 源代码 --> 解压到 X:\sqlite3 目录下 --> 把 X:\Qt\Qt4.8.7\4.8\msvc2008\bin\; 改为 X:\Qt\Qt4.8.7_x64_custom\4.8\msvc2010_64\bin\; 添加到 path 环境变量

到 http://mirrors.ustc.edu.cn/kde/stable 下载 qtwebkit-2.3.4.tar.gz 源代码 --> 解压到 X:\qtwebkit-2.3.4 目录下 --> Visual Studio x64 Win64 Command Prompt (2010) --> X: --> cd .cd .\qtwebkit-2.3.4 --> set SQLITE3SRCDIR=X:\sqlite3 --> set QTDIR=X:\Qt\Qt4.8.7_x64_custom\4.8\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\Qt4.8.7_x64_custom\4.8\msvc2010_64\lib\; 添加到 path 环境变量 --> 双击运行 X:\qtwebkit-2.3.4\WebKitBuild\Release\bin\QtTestBrowser.exe

注意事项


Qt4.8.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

Qt4.8.1\qtwebengine --> warning C4819: 该文件包含不能在当前代码页(936)中表示的字符。请将该文件保存为 Unicode 格式以防止数据丢失 --> qtcreator --> 工具 --> 选项 --> 文本编辑器 --> 行为 --> UTF-8 BOM: 如果编码是 UTF-8 则添加 --> 打开文件 --> 保存文件

相关工具或软件,请跳转 下载中心

若仍不会编译,可联系 客服 寻求帮助 (或关注乐数软件相关在线资源)。

configure 选项


Qt 4.8.7 在 CMD 窗口, configure -help 输出信息。

X:\Qt\qt-everywhere-opensource-src-4.8.7>configure -help
Found more than one known compiler! Using "Microsoft (R) 32-bit C/C++ Optimizing Compiler.NET 2015 (14.0)"
Unable to detect the platform from environment. Use -platform command lineargument or set the QMAKESPEC environment variable and run configure again
See the README file for a list of supported operating systems and compilers.
Usage: configure [-buildkey <key>]
       [-release] [-debug] [-debug-and-release] [-shared] [-static]
       [-no-fast] [-fast] [-no-exceptions] [-exceptions]
       [-no-accessibility] [-accessibility] [-no-rtti] [-rtti]
       [-no-stl] [-stl] [-no-sql-<driver>] [-qt-sql-<driver>]
       [-plugin-sql-<driver>] [-system-sqlite] [-arch <arch>]
       [-D <define>] [-I <includepath>] [-L <librarypath>]
       [-help] [-no-dsp] [-dsp] [-no-vcproj] [-vcproj]
       [-no-qmake] [-qmake] [-dont-process] [-process]
       [-no-style-<style>] [-qt-style-<style>] [-redo]
       [-saveconfig <config>] [-loadconfig <config>]
       [-qt-zlib] [-system-zlib] [-no-gif] [-no-libpng]
       [-qt-libpng] [-system-libpng] [-no-libtiff] [-qt-libtiff]
       [-system-libtiff] [-no-libjpeg] [-qt-libjpeg] [-system-libjpeg]
       [-no-libmng] [-qt-libmng] [-system-libmng] [-no-qt3support] [-mmx]
       [-no-mmx] [-3dnow] [-no-3dnow] [-sse] [-no-sse] [-sse2] [-no-sse2]
       [-no-iwmmxt] [-iwmmxt] [-openssl] [-openssl-linked]
       [-no-openssl] [-no-dbus] [-dbus] [-dbus-linked] [-platform <spec>]
       [-qtnamespace <namespace>] [-qtlibinfix <infix>] [-no-phonon]
       [-phonon] [-no-phonon-backend] [-phonon-backend]
       [-no-multimedia] [-multimedia] [-no-audio-backend] [-audio-backend]
       [-no-script] [-script] [-no-scripttools] [-scripttools]
       [-no-webkit] [-webkit] [-webkit-debug]
       [-graphicssystem raster|opengl|openvg]
       [-no-directwrite] [-directwrite] [-no-nis] [-nis] [-qpa]
       [-no-cups] [-cups] [-no-iconv] [-iconv] [-sun-iconv] [-gnu-iconv]
       [-neon] [-no-neon] [-largefile] [-little-endian] [-big-endian]
       [-font-config] [-no-fontconfig] [-posix-ipc]
 
Installation options:
 
 You may use these options to turn on strict plugin loading:
 
    -buildkey <key> .... Build the Qt library and plugins using the specified
                         <key>.  When the library loads plugins, it will only
                         load those that have a matching <key>.
 
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.
 
    -opensource ........ Compile and link the Open-Source Edition of Qt.
    -commercial ........ Compile and link the Commercial Edition of Qt.
 
    -developer-build ... Compile and link Qt with Qt developer options
                         (including auto-tests exporting)
 
 *  -shared ............ Create and use shared Qt libraries.
    -static ............ Create and use static Qt libraries.
 
    -ltcg .............. Use Link Time Code Generation. (Release builds only)
 *  -no-ltcg ........... Do not use Link Time Code Generation.
 
 *  -no-fast ........... Configure Qt normally by generating Makefiles for all
                         project files.
    -fast .............. Configure Qt quickly by generating Makefiles only for
                         library and subdirectory targets.  All other Makefiles
                         are created as wrappers which will in turn run qmake
 
    -no-exceptions ..... Disable exceptions on platforms that support it.
 *  -exceptions ........ Enable exceptions on platforms that support it.
 
    -no-accessibility .. Do not compile Windows Active Accessibility support.
 *  -accessibility ..... Compile Windows Active Accessibility support.
 
    -no-stl ............ Do not compile STL support.
 *  -stl ............... Compile STL 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-qt3support ..... Disables the Qt 3 support functionality.
 
    -no-opengl ......... Disables OpenGL functionality
 
    -opengl <api> ...... Enable OpenGL support with specified API version.
                         Available values for <api>:
 *                         desktop - Enable support for Desktop OpenGL
                           es1 - Enable support for OpenGL ES Common Profile
                           es2 - Enable support for OpenGL ES 2.0
 *  -no-openvg ......... Disables OpenVG functionality
 
    -openvg ............ Enables OpenVG functionality
                         Requires EGL support, typically supplied by an OpenGL
                         or other graphics implementation
 
    -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.
 
 *  -no-nis ............ Do not build NIS support.
    -nis ............... Build NIS support.
    -qpa ............... Enable the QPA build. QPA is a window system agnostic
                         implementation of Qt.
    -neon .............. Enable the use of NEON instructions.
 *  -no-neon ........... Do not enable the use of NEON instructions.
    -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
    -inotify ........... Enable Qt inotify(7) support.
 
 *  -no-inotify ........ Disable Qt inotify(7) support.
 
 *  -largefile ......... Enables Qt to access files larger than 4 GB.
 *  -little-endian ..... Target platform is little endian (LSB first).
    -big-endian ........ Target platform is big endian (MSB first).
    -fontconfig ........ Build with FontConfig support.
 *  -no-fontconfig ..... Do not build with FontConfig support.
    -posix-ipc ......... Enable POSIX IPC.
    -system-proxies .... Use system network proxies by default.
 *  -no-system-proxies . Do not use system network proxies by default.
    -qtnamespace <namespace> 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.
 
    -graphicssystem <sys> Specify which graphicssystem should be used.
                          Available values for <sys>:
 *                         raster - Software rasterizer
                           opengl - Using OpenGL acceleration, experimental!
                           openvg - Using OpenVG acceleration, experimental!
 
    -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
 
    -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-libmng ......... Do not compile MNG support.
    -qt-libmng ......... Use the libmng bundled with Qt.
 +  -system-libmng ..... Use libmng from the operating system.
                         See See http://www.libmng.com
 
    -no-libtiff ........ Do not compile TIFF support.
    -qt-libtiff ........ Use the libtiff bundled with Qt.
 +  -system-libtiff .... Use libtiff from the operating system.
                         See http://www.libtiff.org
 
    -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
 
Qt for Windows only:
 
    -no-dsp ............ Do not generate VC++ .dsp files.
 *  -dsp ............... Generate VC++ .dsp files, only if spec "win32-msvc".
 
    -no-vcproj ......... Do not generate VC++ .vcproj files.
 *  -vcproj ............ Generate VC++ .vcproj files, only if platform
                         "win32-msvc.net".
 
    -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.
 
    -dont-process ...... Do not generate Makefiles/Project files. This will
                         override -no-fast if specified.
 *  -process ........... Generate Makefiles/Project files.
 
    -no-rtti ........... Do not compile runtime type information.
 *  -rtti .............. Compile runtime type information.
 
    -no-mmx ............ Do not compile with use of MMX instructions
 +  -mmx ............... Compile with use of MMX instructions
    -no-3dnow .......... Do not compile with use of 3DNOW instructions
 +  -3dnow ............. Compile with use of 3DNOW instructions
    -no-sse ............ Do not compile with use of SSE instructions
 +  -sse ............... Compile with use of SSE instructions
    -no-sse2 ........... Do not compile with use of SSE2 instructions
 +  -sse2 .............. Compile with use of SSE2 instructions
    -no-openssl ........ Do not compile in OpenSSL support
 +  -openssl ........... Compile in run-time OpenSSL support
    -openssl-linked .... Compile in linked OpenSSL support
    -no-dbus ........... Do not compile in D-Bus support
 +  -dbus .............. Compile in D-Bus support and load libdbus-1 dynamicall
                         y
    -dbus-linked ....... Compile in D-Bus support and link to libdbus-1
    -no-phonon ......... Do not compile in the Phonon module
 +  -phonon ............ Compile the Phonon module (Phonon is built if a decent
                         C++ compiler is used.)
    -no-phonon-backend . Do not compile the platform-specific Phonon backend-pl
                         ugin
 *  -phonon-backend .... Compile in the platform-specific Phonon backend-plugin
    -no-multimedia ..... Do not compile the multimedia module
 *  -multimedia ........ Compile in multimedia module
    -no-audio-backend .. Do not compile in the platform audio backend into QtMu
                         ltimedia
 +  -audio-backend ..... Compile in the platform audio backend into QtMultimedi
                         a
    -no-webkit ......... Do not compile in the WebKit module
 +  -webkit ............ Compile in the WebKit module (WebKit is built if a
                         decent C++ compiler is used.)
    -webkit-debug ...... Compile in the WebKit module with debug symbols.
    -no-script ......... Do not build the QtScript module.
 +  -script ............ Build the QtScript module.
    -no-scripttools .... Do not build the QtScriptTools module.
 +  -scripttools ....... Build the QtScriptTools module.
    -no-declarative .... Do not build the declarative module
 +  -declarative ....... Build the declarative module
    -no-declarative-debug Do not build the declarative debugging support
 *  -declarative-debug . Build the declarative debugging support
 *  -no-directwrite .... Do not build support for DirectWrite font rendering
    -directwrite ....... Build support for DirectWrite font rendering
                         (experimental, requires DirectWrite availability on
                         target systems, e.g. Windows Vista with Platform
                         Update, Windows 7, etc.)
    -arch <arch> ....... Specify an architecture.
                         Available values for <arch>:
 *                         windows
                           windowsce
                           symbian
                           boundschecker
                           generic
 
    -no-style-<style> .. Disable <style> entirely.
    -qt-style-<style> .. Enable <style> in the Qt Library.
                         Available styles:
 *                         windows
 +                         windowsxp
 +                         windowsvista
 *                         plastique
 *                         cleanlooks
 *                         motif
 *                         cde
                           windowsce
                           windowsmobile
                           s60
 
    -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-iwmmxt ......... Do not compile with use of IWMMXT instructions
 +  -iwmmxt ............ Do compile with use of IWMMXT instructions (Qt for
                         Windows CE on Arm 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
 *  -phonon-wince-ds9 .. Enable Phonon Direct Show 9 backend for Windows CE
 
Qt for Symbian OS only:
 
 *  -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.
    -fpu <flags> ....... VFP type on ARM, supported options: softvfp(default) |
                         vfpv2 | softvfp+vfpv2
    -no-s60 ............ Do not compile in S60 support.
 *  -s60 ............... Compile with support for the S60 UI Framework
    -no-usedeffiles .... Disable the usage of DEF files.
    -usedeffiles ....... Enable the usage of DEF files.
 
X:\Qt\qt-everywhere-opensource-src-4.8.7>
					

版权声明: 本文为独家原创稿件,版权归 乐数软件 ,未经许可不得转载。