源码编译debug版 Qt5.14.0

源码编译debug版 Qt5.14.0

1. 下载源码:
https://download.qt.io/archive/qt/5.14/5.14.0/single/qt-everywhere-src-5.14.0.tar.xz
522M

    1.1. 解压缩:

    tax -xvf qt-everywhere-src-5.14.0.tar.xz
    得到 qt-everywhere-src-5.14.0 目录, 来到这个目录进行配置和编译.

    1.2. cd qt-everywhere-src-5.14.0

2. 配置:
./configure -prefix /storage/build_qt5.14 -debug -opensource -confirm-license -no-openssl -no-opengl -qt-xcb -skip qtquickcontrols -skip qtquickcontrols2 -skip qtsensors -skip qtdoc -no-compile-examples

第二次编译make时碰到了问题,有一堆函数连接不上我也不知道连接什么库。把配置简化一下,参见后面配置,不仅编译快而且能编过。

解释一下

    prefix 是一会儿install的路径,如果不制定,就会安装到默认的/usr/local/ 下, 所以你先要mddir -p /storage/build_qt5.14 确保该目录存在.
    debug 是编译debug版本的Qt
    opensource 是选定开源版本
    confirm-license 是确定下协议
    其它的参数可以忽略掉

结束会提示,可以make了。

曾经遇到过瞪着眼睛看配置不过去,明明zstd 手工运行都可以通过,需要的依赖都给了,./configure 还是不过,报得错误也莫名其妙, make clean 也不管用,看configure 文件太难过了,  全部删除,重新解压再配置通过。

3. 编译

确认一下gcc 的版本,我的是 $gcc -v
gcc version 9.4.0 (Ubuntu 9.4.0-1ubuntu1~20.04.1)

我的机器16核, 于是:
make -j16
还是要等一会的. 编译的过程遇到了缺少 python 的问题, sudo apt install python 解决.

编译是一种编过没有成就感,编不过就过不去的苦差事,面对一些新名字,新名词,新错误无从下手,不知道什么原因及如何处理, 有时候还是参考随软件的README来解决问题吧。

对于一些编不过的又不重要的模块,我还是采取了一些粗暴的做法, 例如修改.pro 或者Makefile 等.

以此来跳过某些module,例如 quick 模块,qtdeclarative 目录等.

还是用简单的配置文件吧: 下面配置可跳过很多模块,编译快,通过。

-prefix /storage/build_qt5.14 -debug -opensource -confirm-license -no-openssl -no-opengl -qt-xcb -skip qt3d  -skip qtquickcontrols  -skip qtwebchannel  -skip qtactiveqt  -skip qtandroidextras  -skip qtdeclarative  -skip qtimageformats  -skip qtmacextras  -skip qtx11extras  -skip qtxmlpatterns  -skip qtconnectivity  -skip qtdoc  -skip qtgraphicaleffects  -skip qtlocation  -skip qtmultimedia  -skip qtsensors  -skip qttools  -skip qttranslations  -skip qtwayland  -skip qtwebchannel  -skip qtwebengine  -skip qtwinextras  -no-compile-examples


make install

文件已被安装到 prefix 指定的目录 /storage/build_qt5.14 目录下
$ ls
bin  doc  examples  include  lib  mkspecs  plugins  qml


4. 确认:
到bin 目录下:
$ ./qmake -v
QMake version 3.1
Using Qt version 5.14.0 in /storage/build_qt5.14/lib

如此新编译的带debug 信息的qt5.14.0已经生成. 后面就是使用的问题了.
只要搞定了qmake, 它自动找头文件(include)和库文件(lib)
单步执行,可以跟踪到Qt模块的代码里, 确实很爽了, 不过很大的代码量,视情况量力而行,拿来主义了.

5. 遇到字体问题及解决方法

QFontDatabase: Cannot find font directory /storage/build_qt5.14/lib/fonts.
Note that Qt no longer ships fonts. Deploy some (from https://dejavu-fonts.github.io/ for example) or switch to fontconfig.
结果是qt 程序显示不出文字.

解决方法:

跟踪了能显示字体的程序访问的是/usr/share/fonts/vista YaHei字体, 所以建立 lib/fonts 目录

copy /usr/share/fonts/vista  YaHei 字体.到指定的fonts 目录即可. 对字体库的访问又多了一层认识.

/usr/share/fonts/vista$ cp YaHei\ Consolas\ Hybrid.ttf /storage/build_qt5.14/lib/fonts/

哇,真棒,这才是真正解决问题.

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值