Win7下静态编译QT5.12源码

官方参考文档:https://doc.qt.io/qt-5/build-sources.html html

CSDN博客:http://www.javashuo.com/article/p-qnkpctlj-ks.htmlpython

博客园博客:https://www.cnblogs.com/BuildingIT/archive/2013/03/22/2976480.html c++

 

安装QT有两种方式:web

  1. 经过QT安装包(Windows下exe文件)
  2. 经过QT源码

 

下文主要描述QT源码的编译方法,QT版本为5.12 sql

下载源码:http://download.qt.io/archive/qt/5.12/5.12.0/single/ api

PS:我下载时遇到的一个插曲,直接在浏览器中点击红线处下载的zip文件解压不了,提示损坏了,最后右键菜单"复制连接地址"使用迅雷精简版下载后能够正常解压使用!浏览器

Windows平台相关支持须要:工具

 

我解压到F:\qt-everywhere-src-5.12.0,能够看到里面有configure文件,在此处使用 configure -h 能够看到可配置的参数,太多了这里只列举几个比较常设置的:ui

-release             Compile and link Qt with debugging turned off. spa

-debug              Compile and link Qt with debugging turned on.

-debug-and-release           Build two versions of Qt.

-shared                          Build shared Qt libraries [yes] (no for UIKit)

-static                         Build static Qt libraries [no] (yes for UIKit)

-nomake tests            Disable building of tests to speed up compilation

-nomake examples         Disable building of examples to speed up compilation

-confirm-license         Automatically acknowledge the LGPL 2.1 license.

-no-opengl                     Disable OpenGL support

-opengl <api>                     Enable OpenGL support.Support APIs:

                              es2 <default on Windows>

                              desktop <default on Unix>

                              dynamic <Windows only>

-opengles3                   Enable OpenGL ES3.x support instead of ES2.x [auto]

 

Windows编译须要准备以下工具:

Python 2.7及以上版本(若是编译WebKit >=2.6.x):下载地址https://www.python.org/downloads/

Perl 5.12 以上版本(必须安装且版本>=5.14):下载地址https://www.activestate.com/activeperl/downloads

支持C++11的编译器,MSVC2012以上版本或者MinGW4.9以上版本

 

Qt编译有两种控制方式:
一、取决因而否使用什么层次的OpenGL API:这里有三个选择:-opengl desktop、-opengl es2和-no-opengl,未来还会增长-opengl es3;
二、若是选用OpenGL ES 2的API渲染的话,Qt也给出了三种方案:-no-angle,直接使用OpenGL的API进行渲染,须要显卡厂商支持OpenGL ES 2.0,对应libGLESv2.dll、libEGL.dll;-angle,若是客户机器不支持OpenGL ES 2.0渲染,可是支持OpenGL 1.5,或者支持DirectX 9.0,那么可使用-angle这个解决方案转换为DirectX的渲染API进行渲染,须要D3DCompiler_4(x).dll以及libGLESv2.dll、libEGL.dll;-angle-d3d11,若是客户机器支持DirectX 11(须要Windows 7以上,一般状况也支持OpenGL ES 2.0),想用最新的DirectX API进行渲染,那么可使用这个方法进行编译。

 

以编译静态库为例

Windows

msvc版

configure -confirm-license -opensource -platform win32-msvc -debug-and-release -static -static-runtime -force-debug-info -opengl dynamic -prefix "./build" -qt-sqlite -qt-pcre -qt-zlib -qt-libpng -qt-libjpeg -opengl desktop -qt-freetype -nomake tests -no-compile-examples -nomake examples

mingw版

configure -confirm-license -opensource -platform win32-g++ -debug-and-release -static -static-runtime -force-debug-info -opengl dynamic -prefix "./build" -qt-sqlite -qt-pcre -qt-zlib -qt-libpng -qt-libjpeg -opengl desktop -qt-freetype -nomake tests -no-compile-examples -nomake examples

Linux

./configure -confirm-license -opensource -debug-and-release -static -static-runtime -force-debug-info -opengl dynamic

 

[个人配置-mingw版]

configure -prefix "./build" -release -opensource –static -static-runtime  -force-debug-info -opengl dynamic -opengl desktop -platform win32-g++ -c++std c++11 -skip qtwebengine -nomake examples -nomake tests -mp -confirm-license

 

配置完成后会生成Makefile文件

[nmake/mingw32-make/make]

使用对应平台下的编译工具(nmake是MSVC的make,mingw32-make是g++的Windows版本的make,make是Linux中的make),若是没有请安装好,此过程比较长,大概一个小时以上,漫长的等待中……

 

[nmake/mingw32-make/make] install

安装成功后,应该能够在./build目录下看到以下文件夹:

若是是静态编译,在lib中能够看到.a库,动态的则是.dll或者.so库

在bin目录下,qt助手、qt设计师、qt翻译家等也都编译出来了~

可是没有qt creater,这须要单独下载qt creater的源码单独编译!

 

QT静态库的使用:

打开QT Creater,运行qt自带的例子boxes,使用默认的MinGW配置编译会编译不过,提示错误: This example requires Qt to be configured with -opengl desktop

缘由是默认的Windows版本的QT使用的编译选项是-opengl dynamic,而boxes例子中使用了原生的opengl绘图,须要-opengl desktop才能使用。咱们上述编译的qt静态库特地配置了-opengl desktop选项。

 

"工具"->"选项"->"Kits":

添加Qt Versions,将咱们上述编译的qt静态库build目录中的qmake添加:

配置构建套件(Kit),手动设置"桌面"配置以下:

打开boxes工程,配置"桌面"编译选项,执行build操做

等待大约2分钟左右,boxes例程终于能够成功编译了~

运行吧!

相关文章
相关标签/搜索