[Qt] Linux环境下从源码编译Qt

官网参考:

Qt for Linux/X11 - Building from Source | Qt 5.15

源码下载:

Index of /archive/qt/5.15/5.15.0/submodules

这里使用的是各个模块单独编译,这样有助于摸清各个模块之间的依赖关系

工程配置Configure:

默认情况下,可以直接运行 ./configure ,如果想增加定制化需求,则需要自行指定参数:

============== 全局 install相关 ==============

-prefix <dir>         重定向make install 动作的路径

-extprefix <dir>       交叉编译相关

-hostprefix [dir]       交叉编译相关

-external-hosstbindir <path>        交叉编译相关  

============== 子 install相关 ==============

-bindir <dir>        二进制文件的install 路径,默认是 prefix/bin

-headerdir <dir>        头文件install路径,默认是 prefix/include

-libdir <dir>        lib文件install路径,默认是prefix/lib

-archdatadir <dir>        架构相关文件isntall路径,默认是prefix

-plugindir <dir>        插件install路径,默认是 archdatadir/plugins

-libexecdir <dir>        帮助文档程序(assistant)install路径,windows下默认是

                                 archdatadir/bin,linux下默认是archdatadir/libexec

-importdir <dir>        QML1 安装路径,默认archdatadir/imports

-qmldir <dir>         QML2 安装路径,默认是archdatadir/qml

-datadir <dir>        架构无关文件install路径,默认是 prefix

-docdir <dir>         文档安装路径,默认是 datadir/doc

-translationdir <dir>        多语言相关安装路径,默认是 datadir/translations

-sysconfdir <dir>        一些配置信息,默认是 prefix/etc/xdg,没看到过

-examplesdir <dir>        例子,默认prefix/examples

-testsdir <dir>        测试用例,默认prefix/tests

-hostbindir <dir>        交叉编译相关,指定主机的bin目录,对应 -bindir,默认 hostprefix/bin

-hostlibdir <dir>        交叉编译相关,指定主机的lib目录,对应 -libdir,默认 hostprefix/lib

-hostdatadir <dir>        交叉编译相关,指定主机的data目录,对应 -datadir,默认hostprefix

============== configure 元语 ==============

-help,-h        帮助

-verbose,-v        输出详尽信息

-continue        当configure出现error时直接忽略从而继续执行

-redo        使用上一次configure的选项,如果本次指定了新选项,则这些新选项不会被保

                 存,也就是说再做 -redo的时候还是使用刚才的 configure 选项

-recheck [test,... ]        ???

-recheck-all        ???

-feature-<feature>        开启某个特性,具体的特性

-no-feature-<feature>        关闭某个特性,具体的特性

-list-features        罗列所有特性

-list-libraries        罗列所有可能用到的外部依赖库

============== 构建选项 ==============

-opensource        构建开源版本

-commercial        构建商业版本

-confirm-license        自动选择license

-release        构建release版

-debug        构建debug版

-debug-and-release        同时否建debug和release

-optimize-debug        优化调试信息(MSVC 和 clang 无效)

-optimize-size        对输出二进制文件进行尺寸优化,但是运行速度可能会慢一点

-optimize-tools        交叉编译相关,是否优化工具

-force-debug-info        为release创建符号文件

-separate-debug-info        把调试信息裁剪出来

-gdb-index        gdb加速

-strip        为release版裁剪不必要的符号

-gc-binaries        编译时垃圾回收,不太需要关心,静态库会自动触发此选项

-force-asserts        开启Q_ASSERT,即使是构建release版本

-developer-build        编译链接Qt用作开发Qt自身

-shared        构建动态库

-static        构建静态库

-framework        仅Apple用,构建Qt framework bundles

-platform <target>        指定目标平台的mkspec,target是mkspec文件

-xplatform <target>        指定目标平台的mkspec,target是mkspec文件,用于交叉编译

-device <name>        交叉编译设备名

-device-option <key=value>        为mkspec增加指定选项,用于交叉编译

-appstore-compliant        应用发布相关

-qtnamespace <name>        把所有的Qt库都用此命名空间包裹,这样可以用来区分不同版

                                             本,使用时如:Qt5::QString,MyQt::QString

-qtlibinfix <infix>        把所有的 libQt5*.so 重命名为 libQt5*<infix>.so

-qtlibinfix-plugins        是否按照-qtbinfix指定的 infix 值重命名 Qt 插件

-testcocoon        ???

-gcov        ???

-trace [backend]        backend可以是etw(windows)或者lttng(linux),指定trace工具

-sanitize {address|thread|memory|fuzzer-no-link|undefined}        编译相关

-coverage {trace-pc-guard|source-based}        为sanitizer提供服务

-c++std <edition>        指定c++版本,可以是 c++2a、c++17、c++14、c++11

-sse2        使用sse2指令集

-sse3/-ssse3/-sse4.1/-sse4.2/-avx/-avx2/avx512        使用指定的指令集

-mips_dsp/-misp_dspr2        MISP相关

-qreal <type>        重定义 qreal 类型对应的实际类型

-R <string>        以libdir为参考路径,为Qt库指定一个运行时库搜索路径

-rpath                同上一个

-reduce-exports        减少到处符号数量

-reduce-relocations        ???

-plugin-manifests        为plugins增加manifest,Windows Only

-static-runtime        使用静态runtime库,Windows Only

-pch        使用预编译头

-ltcg        使用 Link Time Code Generation

-linker [bfd,gold,lld]        使用 GNU ld,GNU gold 或者 LLVM/LLD 这些链接器,gcc only

-incredibuild-xge        使用IncrediBuild XGE,Windows Only

-ccache        使用ccache编译器缓存,Unix Only

-make-tool <tool>        使用指定tool编译qmake,默认是nmake , Windows Only

-mp        多处理器编译,Windows Only

-warnings-are-errors        把warnings当做error

-silent        减少编译提示

============== 构建环境 ==============

-sysroot <dir>        设置目标sysroot???

-gcc-sysroot        ???

-pkg-config        使用pkg-config,Unix Only

-D  <string>        额外的编译宏定义

-I  <string>        额外的include路径

-L  <string>        额外的库路径

-F  <string>        额外的framework 路径,Apple Only

-sdk  <sdk>        Apple Only,不关心

-android-sdk path

-android-ndk path

-android-ndk-platform

-android-ndk-host

-android-abis

-android-style-assets

============== 组件选择 ==============

-skip <repo>        跳过源码路径下的某个文件夹,repo对应文件夹名,比如 -skip qtcharts则

                            qtchart便不会被编译到当前工程中。

-make <part>        指定编译哪个模块,part对应???,注意,如果使用这个选项,则所

                             有默认值都会被取消,也就是说我们必须一个个地指定要编译的模块,一

                             般不建议使用。

-nomake <part>        和-make互斥,和-skip什么区别????

-compile-examples        如果指定,则例子不会被编译,只会保留源码,这个选项一般会被指

                                      定,从而提高编译速度,例子可以在用到的时候直接当工程打开。

-gui        编译GUI模块及其依赖模块

-widgets        编译widget模块及其依赖模块

-no-bus        不要编译D-Bus模块

-dbus-linked        编译D-Bus并把它链接到libdbus-1中

-dbus-runtime        编译D-Bus并动态加载libdbus-1,对比-dbus-linked

-accessibility        开启accessibility支持

============== Qt Core 相关 ==============

-doubleconversion        使用double conversion 库,不实用 sscanf_l 和 snprintf_l

-glib        开启Glib

-eventfd        开启eventfd支持,eventfd是linux环境下的事件机制

-inotify        开启inotify支持,inotify用来监控文件描述符

-iconv        开启iconv支持

-icu        开启ICU支持

-pcre        使用libpcre2

-pps        开启PPS支持

-zlib        使用zlib

-journald        使用journald支持

-syslog        使用syslog支持

-slog2        使用slog2支持

============== 网络相关 ==============

-ssl        开启SSL

-no-openssl        关闭OpenSSL

-openssl-linked        使用并链接到libssl

-openssl-runtime        使用并动态加载libssl

-schannel        使用Secure Channel

-securetransport        使用SecureTransport

-sctp        开启SCTP支持

-libproxy        使用libproxy

-system-proxies        使用系统网络代理

============== Gui 、printing、widget 相关选项 ==============

-cups        开启CUPS支持

-fontconfig        开启Fontconfig支持

-freetype        select used freetype

-harfbuzz        select used harfbuzz-ng

-gtk        开启GTK平台主题

-lgmon        开启lgmon支持

-no-opengl        关闭opengl支持

-opengl <api>        开启opengl支持,同时指定api类型,可选为 es2 、desktop、dynamic

-opengles3        使用OpenGL ES 3.x,代替ES 2.x

-egl        开启EGL支持

-angle        使用ANGLE作为OpenGL ES 2.0的底层实现

-combined-angle-lib        把libEGL和 libGLESv2 合并到 LibANGLE中

-qpa <name>        选择默认的QPA后台,比如xcb,cocoa,windows

-xcb-xlib        开启Xcb-Xlib

============== 平台底层支撑 ==============
    -direct2d .......... Enable Direct2D support [auto] (Windows only)
    -directfb .......... Enable DirectFB support [no] (Unix only)
    -eglfs ............. Enable EGLFS support [auto; no on Android and Windows]
    -gbm ............... Enable backends for GBM [auto] (Linux only)
    -kms ............... Enable backends for KMS [auto] (Linux only)
    -linuxfb ........... Enable Linux Framebuffer support [auto] (Linux only)
    -xcb ............... Enable X11 support [auto] (Linux only)

============== 输入底层支撑 ==============
    -libudev............ Enable udev support [auto]
    -evdev ............. Enable evdev support [auto]
    -imf ............... Enable IMF support [auto] (QNX only)
    -libinput .......... Enable libinput support [auto]
    -mtdev ............. Enable mtdev support [auto]
    -tslib ............. Enable tslib support [auto]
    -bundled-xcb-xinput  Use bundled XInput2 support [auto]
    -xkbcommon ......... Enable key mapping support [auto]

============== 图片格式 ==============
    -gif ............... Enable reading support for GIF [auto]
    -ico ............... Enable support for ICO [yes]
    -libpng ............ Select used libpng [system/qt/no]
    -libjpeg ........... Select used libjpeg [system/qt/no]

============== 数据库选项 ==============

  -sql-<driver> ........ Enable SQL <driver> plugin. Supported drivers:
                         db2 ibase mysql oci odbc psql sqlite2 sqlite tds
                         [all auto]
  -sqlite .............. Select used sqlite3 [system/qt] 

第三方库支撑:

Qt依赖很多第三方库,同时Qt的源码中也会包含这些库的源码,我们可以选择使用Qt自带的第三方库,或者选择使用自己指定的第三方库。

Library NameBundled in QtInstalled in System
zlib-qt-zlib-system-zlib
libjpeg-qt-libjpeg-system-libjpeg
libpng-qt-libpng-system-libpng
freetype-qt-freetype-system-freetype
PCRE-qt-pcre-system-pcre
HarfBuzz-NG-qt-harfbuzz-system-harfbuzz

注意,也可以指定某些库使用qt自带的,某些库使用系统的。比如:

./configure -no-zlib -qt-libjpeg -qt-libpng -system-xcb

如果没有特殊定制,可以考虑使用Qt源码中自带的库。

编译选项:

前面的 configure 选项中提到了 -platform 选项,这是用来指定目标平台的,不同的Qt版本也对于最低的操作系统版本也有要求,同样对于编译器也有要求。

Supported Platforms | Qt 5.15

在源码中的体现是,不同的platform有自己专属的 mkspec 文件,文件路径为 qtbase/mkspecs,当通过 -platform 指定某个平台时,configure就会加载对应的 spec 文件。

例如:

./configure -platform linux-clang   # linux-clang为 qtbase/mkspecs目录下的一个目录名
./configure -platform linux-g++     # linux-g++为 qtbase/mkspecs目录下的一个目录名
./configure -platform linux-g++-32

可见,不仅区别 操作系统 及 位数,还会区别编译器。

交叉编译:

参考:Qt Configure Options | Qt 5.15

Windows平台下的OpenGL选项:

参考:Qt Configure Options | Qt 5.15

开发者模式:

使用 -developer-build开启开发者模式,开发者模式编译出来的工程包含最完整的符号信息和最全的告警提示。

重新配置:

configure脚本会在当前执行命令的目录下形成MakeFile 和 配置缓存,注意不是在configure文件所在目录,所以如果想要配置多个版本的构建策略,只需要创建多个目录,然后在各个目录下跨目录运行configure脚本即可。如果想要修改当前配置,则需要先运行make confclean  然后再进行configure。

构建Qt 文档:

Qt帮助文档要单独构建,再Makefile所在目录下运行:

make  docs

  • 2
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值