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

CSDN博客:https://blog.csdn.net/GG_SiMiDa/article/details/78517246

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

安装QT有两种方式:

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

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

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

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

Windows平台相关支持需要:

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

-release             Compile and link Qt with debugging turned off.

-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编译有两种控制方式:
1、取决于是否使用什么层次的OpenGL API:这里有三个选择:-opengl desktop、-opengl es2和-no-opengl,将来还会增加-opengl es3;
2、如果选用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例程终于可以成功编译了~

运行吧!

Win7下静态编译QT5.12源码的更多相关文章

  1. msvc2013编译qt5.6源码

    1.回顾 说起到qt的编译,真是领人痛心啊,不仅编译选项繁多,而且编译时间比较久,总是能使想编译qt源码的人望而却步,呵呵...我就是其中一个,不知道从什么时候开始就想着把qt的源码编译一下,也尝试过 ...

  2. MAC 下编译 ANDROID P 源码 提示 internal error: Could not find a supported mac sdk: ["10.10" "10.11" "10.12" "10.13"]

    MAC 下编译 ANDROID P 源码出现下面的问题: ninja: no work to do. [21/21] out/soong/.bootstrap/bin/soong_build out/ ...

  3. windows下使用mingw和msvc静态编译Qt5.15.xx

    windows下使用mingw和msvc静态编译Qt5.15.xx 下载并安装相关依赖软件 Python version 2.7 https://www.python.org/downloads/ ( ...

  4. Ubuntu 14.04 LTS 下 android 2.3.5 源码编译过程

    Ubuntu 14.04 LTS 下 android 2.3.5 源码编译过程   在新的Ubuntu 64位系统下去编译早期的安卓源码是会出现很多问题的,因为64位系统在安装完成后,很多32位的兼容 ...

  5. win7 安装用mingw编译的Qt源码并连接postgresql

    下载Qt 1.下载qt-creator-windows-opensource-2.8.0,下载路径:http://download.qt.io/official_releases/qtcreator/ ...

  6. Win7下VS2008编译QtiPlot

    Win7下VS2008编译QtiPlot By wangsh 2011-11-25 QtiPlot 是一款开源免费的科学绘图软件,可运行在多个平台(windows.Linux等)中,从功能上讲,Qti ...

  7. Ubuntu 下载 & 编译 Android5.1 源码

    ustc & tsinghua android srchttps://lug.ustc.edu.cn/wiki/mirrors/help/aosphttps://mirrors.tuna.ts ...

  8. 编译android5.0源码的

    java环境 Android 5.1 用到的jdk不再是Oracle 的 jdk ,而是开源的 openjdk,在ubuntu安装好后,使用如下命令安装jdk: $sudo apt-get insta ...

  9. 【转】编译Android系统源码和内核源码

    原文网址:http://blog.csdn.net/jiangwei0910410003/article/details/37988637 好长时间没有写blog了,之所以没有写,主要还是工作上的事, ...

随机推荐

  1. JVM内存的设置

    一.JVM内存的设置的原理 默认的java虚拟机的大小比较小,在对大数据进行处理时java就会报错:java.lang.OutOfMemoryError. 设置jvm内存的方法,对于单独的.class ...

  2. 【进阶修炼】——改善C#程序质量(4)

    46, 显示释放资源,需要实现IDisposable接口. 最好按照微软建议的Dispose模式实现.实现了IDisposable接口后,在Using代码块中,垃圾会得到自动清理. 47, 即使提供了 ...

  3. Linux查看cpu个数

    [root@lidongbo~]# cat /proc/cpuinfo processor       : 0 vendor_id       : GenuineIntel cpu family    ...

  4. es 剩余磁盘空间达到es最小值,添加数据被block

    剩余磁盘空间达到es最小值,添加数据被block PUT _all/_settings {"index.blocks.read_only_allow_delete": null} ...

  5. 【转】MySQL分库分表数据迁移工具的设计与实现

    一.背景 MySQL作为最流行的关系型数据库产品之一,当数据规模增大遭遇性能瓶颈时,最容易想到的解决方案就是分库分表.无论是进行水平拆分还是垂直拆分,第一步必然需要数据迁移与同步.由此可以衍生出一系列 ...

  6. 2、QT分析之QPushButton的初始化

    原文地址:http://blog.163.com/net_worm/blog/static/127702419201001003326522/ 在简单的QT程序的第二行,声明了一个QPushButto ...

  7. 《FPGA全程进阶---实战演练》第十四章 蜂鸣器操作

    1 基础理论部分 本实验主要是实现蜂鸣器的操作,蜂鸣器的操作是非常简单的,只有把简单的事情做好,方可谈其他复杂的事.本实验部分会利用verilog一些宏定义语句,其实在VGA实验部分已经出现过,这里为 ...

  8. 实验一 ASP.NET应用环境配置 总结

    通过本次实验我学会了在Windows XP系统中安装IIS服务器,虽然我的电脑是Windows7系统,但是通过虚拟机软件,配置了一台Windows XP系统的虚拟机,在虚拟机内进行各项配置操作.这次实 ...

  9. Linux之查看CPU

    # 总核数 = 物理CPU个数 X 每颗物理CPU的核数 # 总逻辑CPU数 = 物理CPU个数 X 每颗物理CPU的核数 X 超线程数 # 查看物理CPU个数 cat /proc/cpuinfo| ...

  10. 【转】【Centos】centos 安装libtorrent/rtorrent

    1.下载编译时需要的软件 yum install gcc gcc-c++ m4 make automake libtool pkgconfig perl openssl-devel ncurses-d ...