本文用于记录在国产操作系统:银河麒麟V10(arm64)上从源码编译Qt5.8.0(Qt5.15.2为踩坑版本)
主机环境:
Qt Version:5.8.0
Openssl Version:1.0.2k
参考博客:https://segmentfault.com/a/1190000040169088
Qt 文档: https://doc.qt.io/qt-5/build-sources.html
https://doc.qt.io/qt-5/configure-options.html
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/
#解压
sudo tar xvf qt-everywhere-opensource-src-5.8.0.tar.xz
#进入源码目录
cd qt-everywhere-opensource-src-5.8.0
sudo apt-get build-dep qt5-default
sudo apt-get install libxcb-xinerama0-dev
sudo apt-get install build-essential perl python git
sudo apt-get install '^libxcb.*-dev' libx11-xcb-dev libglu1-mesa-dev libxrender-dev libxi-dev libxkbcommon-dev libxkbcommon-x11-dev
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
sudo apt-get install flex bison gperf libicu-dev libxslt-dev ruby
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
sudo apt-get install libasound2-dev libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev
sudo apt install libclang-6.0-dev llvm-6.0
参考博客:Linux 下 qt5的安装及库编译、qt5的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:重新检查所有依赖项。
官方建议新建一个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
sudo make -j4
sudo make install
在编译完成后执行 make install 会将qt库安装到 -prefix 指定的目录下。
可以使用make clean 清楚编译
使用make uninstall来卸载安装
查看版本信息
# 进入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
原因:目录有中文
解决办法:将源码文件夹放在没有中文的路径
/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
核心问题是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