【Qt】VS2010编译Qt5.3.2 64bit

1. 为什么要这么做

在Windows下,Qt官网默认提供的二进制版本大多是32位,目前(2015.01.24)只对VS2013提供了64位版本,如下图所示:

为了适应我目前安装的VS2010 IDE,也为了根据自己的需要编译特定的库和插件(比如去掉webkit之类),需要直接从源码编译Qt。

本例编译的是Qt5.3.2版本,应该也适用于Qt5.4.0。

2. 准备

首先,当然需要一个C++编译器,由于一些兼容性原因,我需要用Visual C++ 2010, 也可以用MinGW。用MinGW的话还对调试有帮助,这是后话。

另外在Windows上编译Qt需要一些库,参见http://doc.qt.io/qt-5/windows-requirements.html

由于我不需要3D图形,WebKit等支持,因此不需要Opengl, ANGLE, ICU等一堆库,只需要以下3个编译时要用的工具(运行时不需要):

  • ActivePerl - Install a recent version of ActivePerl (download page) and add the installation location to your PATH.
  • Python - Install Python from the here and add the installation location to your PATH in order to be able to build Qt WebKit.
  • Install Ruby from here and add the installation location to your PATH in order to be able to build Qt WebKit.

把这3个玩意儿下载安装上即可。

3. 编译

把下载下来的Qt源码解压至目录<QtDir>,然后在此目录根下创建一个批处理文件,内容如下:

@echo off

ECHO 设置 Visual Studio environment...
CALL "C:Program Files (x86)Microsoft Visual Studio 10.0VCvcvarsall.bat" amd64
title Command Prompt (MSVC++ 2010) x64

SET QTSRC_DIR=H:qt-msvc2010-x64
SET QMAKESPEC=win32-msvc2010

SET PATH=%PATH%;%QTSRC_DIR%qtbasein;%QTSRC_DIR%gnuwin32bin
SET PATH=%PATH%;C:Python27;C:Perl64in;C:Ruby21-x64in;


ECHO 按任意键,进行configure...
@PAUSE>NUL
CALL configure -opensource -mp -debug-and-release -nomake examples -no-opengl -no-angle -skip qtquick1 -skip qtquickcontrols -skip qtsensors -skip qtwebkit

ECHO 按任意键,开始编译...
@PAUSE>NUL
CALL jom.exe -j 4

REM 重新配置和编译请使用
REM nmake distclean 或jom clean

goto :eof

其中设置好了VC++环境变量、源码目录、必备工具执行目录等等;

通过configure设置了需要编译的模块和不需要编译的模块。通过禁止不需要的编译模块,可以大幅加快编译速度;

jom.exe -j 4指定使用4个线程并行编译。

写好保存为bat文件,在命令行执行即可。

原文地址:https://www.cnblogs.com/zzqcn/p/4245325.html