银河麒麟V10(arm64) 源码编译Qt5.8.0

0.前言

本文用于记录在国产操作系统:银河麒麟V10(arm64)上从源码编译Qt5.8.0(Qt5.15.2为踩坑版本)

0.1 编译环境

主机环境:

银河麒麟V10(arm64) 源码编译Qt5.8.0_第1张图片

Qt Version:5.8.0

Openssl Version:1.0.2k

0.2 参考文档

参考博客:https://segmentfault.com/a/1190000040169088

Qt 文档: https://doc.qt.io/qt-5/build-sources.html

​ https://doc.qt.io/qt-5/configure-options.html

1.下载Qt源码

Qt 5.15.2 https://download.qt.io/official_releases/qt/5.15/5.15.2/single/

Qt 5.8.0 https://download.qt.io/new_archive/qt/5.8/5.8.0/

2. 解压源码包

#解压
sudo tar xvf qt-everywhere-opensource-src-5.8.0.tar.xz
#进入源码目录
cd  qt-everywhere-opensource-src-5.8.0

3. 安装编译所依赖的库

3.1 安装基础的编译环境

sudo apt-get build-dep qt5-default
sudo apt-get install libxcb-xinerama0-dev 
sudo apt-get install build-essential perl python git

3.2 按需选择安装其他模块依赖

  • Libxcb
sudo apt-get install '^libxcb.*-dev' libx11-xcb-dev libglu1-mesa-dev  libxrender-dev libxi-dev libxkbcommon-dev libxkbcommon-x11-dev
  • OpenGL
sudo apt-get install build-essential
sudo apt-get install libgl1-mesa-dev
sudo apt-get install libglu1-mesa-dev
sudo apt-get install libegl1-mesa-dev
sudo apt-get install freeglut3-dev
  • Qt WebKit
sudo apt-get install flex bison gperf libicu-dev libxslt-dev ruby
  • Qt WebEngine
sudo apt-get install libssl-dev libxcursor-dev libxcomposite-dev  libxdamage-dev libxrandr-dev libdbus-1-dev libfontconfig1-dev libcap-dev libxtst-dev libpulse-dev libudev-dev libpci-dev libnss3-dev  libasound2-dev libxss-dev libegl1-mesa-dev gperf bison
  • Qt Multimedia
sudo apt-get install libasound2-dev libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev
  • QDoc Documentation Generator Tool
sudo apt install libclang-6.0-dev llvm-6.0

4. 配置编译参数使用影子构建

参考博客:Linux 下 qt5的安装及库编译、qt5的configure选项说明

4.1 configure参数说明

./configure:执行 Qt 的配置脚本。
-confirm-license:自动确认许可
-prefix:指定 Qt 库的安装路径。
-opensource:指定使用开源协议编译 Qt 库。
-openssl-linked:开启该选项将 OpenSSL 链接到 Qt 应用程序中
-I:指定 OpenSSL 头文件的搜索路径。
-L:指定 OpenSSL 库的搜索路径。
-nomake tests:不编译 Qt 库自带的测试程序。
-nomake examples:不编译 Qt 库自带的示例程序。
-recheck-all:重新检查所有依赖项。

4.2 构建

官方建议新建一个build目录,然后在该目录下配置configure,make之类的,这样子配置编译生成的临时文件会放在该目录下,而不会污染源码。

#创建构建目录
mkdir build-5.8.0
#进入构建目录
cd build
#执行构建命令
OPENSSL_LIBS='-L/usr/local/openssl/lib -lssl -lcrypto -ldl' ../qt-everywhere-opensource-src-5.8.0/configure -confirm-license -prefix /opt/qt-5.8.0  -opensource -openssl-linked -I /usr/local/openssl/include -L /usr/local/openssl/lib -nomake tests -nomake examples -skip qtwebengine -recheck-all

5. 编译

5.1 make

sudo make -j4

5.2 make install

sudo make install

在编译完成后执行 make install 会将qt库安装到 -prefix 指定的目录下。

5.3 make clean 清除配置

可以使用make clean 清楚编译

5.4 make uninstall 卸载安装

使用make uninstall来卸载安装

Qt 5 环境变量

查看版本信息

# 进入qmake所在目录
cd /opt/qt-5.8.0/bin
# 查看版本信息
./qmake -v

设置环境变量
打开终端输入以下代码

vim ~/.bashrc

在最后一行加入以下代码

export QTDIR=/opt/qt-5.8.0
export PATH=$QTDIR/bin:$PATH 
export MANPATH=$QTDIR/man:$MANPATH 
export LD_LIBRARY_PATH=$QTDIR/lib:$LD_LIBRARY_PATH

保存退出重启电脑
打开终端输入

qmake -v

成功显示版本号安装完成

原文链接:https://blog.csdn.net/liangjian990709/article/details/111494494

常见问题

报错 Could not find qmake spec ‘’

原因:目录有中文

解决办法:将源码文件夹放在没有中文的路径

Qt5 opensll配置

报错

/home/yh/work/code/Silversea/3rdparty/shftp/shftp/dataconnection.cpp:52: 错误: invalid use of incomplete type ‘class QSslSocket’
         socket = new QSslSocket(this);
                      ^

解决

QSslSocket报错,因为相同代码在不同编译器上报错,排查是不是当前系统环境配置问题

经过对比发现,应该是源码编译时没有开启openssl的支持。

运行 configure 脚本,指定 OpenSSL 库的路径和头文件路径,同时开启 Qt Network -> OpenSSL 选项。例如:

mkdir build-qt5.8.0
cd build-qt5.8.0
../qt-everywhere-opensource-src-5.8.0/configure -prefix /opt/qt-5.8.0  -opensource -openssl-linked -I /usr/local/openssl/include -L /usr/local/openssl/lib -nomake tests -nomake examples -skip qtwebengine -recheck-all

make: *** [module-qtbase-make_first] Error 2

报错信息

核心问题是libcrypto.a中找不到一系列的符号:dlopen、dlsym等

Erratum 843419 found and fixed at ".obj/qnetworkreplyhttpimpl.o", section 66, offset 0x00004bb0.
Erratum 843419 found and fixed at ".obj/qsslcertificate.o", section 10, offset 0x00000f90.
Erratum 843419 found and fixed at ".obj/qnetworkreplyhttpimpl.o", section 66, offset 0x00004bb0.
Erratum 843419 found and fixed at ".obj/qsslcertificate.o", section 10, offset 0x00000f90.
/usr/local/openssl/lib/libcrypto.a(dso_dlfcn.o):dso_dlfcn.c:function dlfcn_globallookup: error: undefined reference to 'dlopen'
/usr/local/openssl/lib/libcrypto.a(dso_dlfcn.o):dso_dlfcn.c:function dlfcn_globallookup: error: undefined reference to 'dlsym'
/usr/local/openssl/lib/libcrypto.a(dso_dlfcn.o):dso_dlfcn.c:function dlfcn_globallookup: error: undefined reference to 'dlclose'
/usr/local/openssl/lib/libcrypto.a(dso_dlfcn.o):dso_dlfcn.c:function dlfcn_bind_func: error: undefined reference to 'dlsym'
/usr/local/openssl/lib/libcrypto.a(dso_dlfcn.o):dso_dlfcn.c:function dlfcn_bind_func: error: undefined reference to 'dlerror'
/usr/local/openssl/lib/libcrypto.a(dso_dlfcn.o):dso_dlfcn.c:function dlfcn_bind_var: error: undefined reference to 'dlsym'
/usr/local/openssl/lib/libcrypto.a(dso_dlfcn.o):dso_dlfcn.c:function dlfcn_bind_var: error: undefined reference to 'dlerror'
/usr/local/openssl/lib/libcrypto.a(dso_dlfcn.o):dso_dlfcn.c:function dlfcn_load: error: undefined reference to 'dlopen'
/usr/local/openssl/lib/libcrypto.a(dso_dlfcn.o):dso_dlfcn.c:function dlfcn_load: error: undefined reference to 'dlclose'
/usr/local/openssl/lib/libcrypto.a(dso_dlfcn.o):dso_dlfcn.c:function dlfcn_load: error: undefined reference to 'dlerror'
/usr/local/openssl/lib/libcrypto.a(dso_dlfcn.o):dso_dlfcn.c:function dlfcn_pathbyaddr: error: undefined reference to 'dladdr'
/usr/local/openssl/lib/libcrypto.a(dso_dlfcn.o):dso_dlfcn.c:function dlfcn_pathbyaddr: error: undefined reference to 'dlerror'
/usr/local/openssl/lib/libcrypto.a(dso_dlfcn.o):dso_dlfcn.c:function dlfcn_unload: error: undefined reference to 'dlclose'
collect2: error: ld returned 1 exit status
Makefile:551: recipe for target '../../lib/libQt5Network.so.5.8.0' failed
make[3]: *** [../../lib/libQt5Network.so.5.8.0] Error 1
make[3]: Leaving directory '/home/yh/work/qt/build5.8/qtbase/src/network'
Makefile:190: recipe for target 'sub-network-make_first' failed
make[2]: *** [sub-network-make_first] Error 2
make[2]: Leaving directory '/home/yh/work/qt/build5.8/qtbase/src'
Makefile:46: recipe for target 'sub-src-make_first' failed
make[1]: *** [sub-src-make_first] Error 2
make[1]: Leaving directory '/home/yh/work/qt/build5.8/qtbase'
Makefile:78: recipe for target 'module-qtbase-make_first' failed
make: *** [module-qtbase-make_first] Error 2

解决办法

在configure构建的时候,openssl编译命令填上 -ldl

#之前的
OPENSSL_LIBS='-L/usr/local/openssl/lib -lssl -lcrypto'
#修改后
OPENSSL_LIBS='-L/usr/local/openssl/lib -lssl -lcrypto -ldl'

参考链接:
https://stackoverflow.com/questions/956640/linux-c-error-undefined-reference-to-dlopen

https://blog.csdn.net/itjobtxq/article/details/51538239

你可能感兴趣的:(QT5,国产系统QT开发,qt,kylin,linux)