1、安装patchelf、cmake
sudo apt install patchelf
sudo apt install cmake
2、下载 linuxdeployqt源码
终端输入指令:git clone https://github.com/probonopd/linuxdeployqt.git
3、将tools/linuxdeployqt/main.cpp中的下述代码注释掉:
// openSUSE Leap 15.0 uses glibc 2.26 and is used on OBS
/*
if (strverscmp (glcv, "2.27") >= 0) { //注释版本检查
qInfo() << "ERROR: The host system is too new.";
qInfo() << "Please run on a system with a glibc version no newer than what comes with the oldest";
qInfo() << "currently still-supported mainstream distribution (xenial), which is glibc 2.23.";
qInfo() << "This is so that the resulting bundle will work on most still-supported Linux distributions.";
qInfo() << "For more information, please see";
qInfo() << "https://github.com/probonopd/linuxdeployqt/issues/340";
return 1;
}*/
4、在主linuxdeployqt-continuous/tools/linuxdeployqt目录下CMakeLists.txt添加
CMAKE_MINIMUM_REQUIRED(VERSION 3.16 FATAL_ERROR)
PROJECT(NEWHELLO)
# ADD_SUBDIRECTORY(src)
set(CMAKE_PREFIX_PATH "/home/start/Qt5.13.2/5.13.2/gcc_64")
set(Qt5_DIR "${CMAKE_PREFIX_PATH}/lib/cmake/Qt5")
set(Qt5Widgets_DIR "${CMAKE_PREFIX_PATH}/lib/cmake/Qt5Widgets")
set(Qt5Network_DIR "${CMAKE_PREFIX_PATH}/lib/cmake/Qt5Network")
set(Qt5LinguistTools_DIR "${CMAKE_PREFIX_PATH}/lib/cmake/Qt5LinguistTools")
5、编译
1、在主linuxdeployqt-continuous/tools/linuxdeployqt目录下输入:
mkdir buile
2、上述执行完毕后再输入:
cmake ../
make
3、生成linuxdeployqt,具体生成路径在:
linuxdeployqt-continuous/tools/linuxdeployqt/buile下
4、修改为可执行权限
chmod 777 linuxdeployqt
5、将可执行文件linuxdeployqt拷贝到/usr/local/bin,方便使用
cp linuxdeployqt /usr/local/bin
6、测试是否安装成功
linuxdeployqt --version
打包
1、Qt库路径设置到环境变量
vim ~/.bashrc
#add qt env
export PATH=/opt/Qt5.13.0/5.13.0/gcc_64/bin:$PATH
export LIB_PATH=/opt/Qt5.13.0/5.13.0/gcc_64/lib:$LIB_PATH
export PLUGIN_PATH=/opt/Qt5.13.0/5.13.0/gcc_64/plugins:$PLUGIN_PATH
export QML2_PATH=/opt/Qt5.13.0/5.13.0/gcc_64/qml:$QML2_PATH
source ~/.bashrc
然后,对环境变量测试下,是否设置正确
qmake -v
打包Qt生成执行文件,名为xx
执行命令
linuxdeployqt xxx -appimage
error: could not start patchelf.
error: make sure it is installed on your $path.
error: error reading rpath with patchelf “libqt5widgets.so” : “”
error: error reading rpath with patchelf “libqt5widgets.so” : “”
这个错误是表明缺少需要的pathchelf工具,直接安装即可解决:
sudo apt install patchelf
然后又出现了下面这个错误:
error: ldd outputline: “libjasper.so.1 => not found”
error: for binary:
“/home/xl/qt5.9.2/5.9.2/gcc_64/plugins/imageformats/libqjp2.so”error: please ensure that all libraries can be found by ldd. aborting.
这表明缺少了libqjp2.so这个库的。缺什么就装什么:
sudo add-apt-repository "deb http://security.ubuntu.com/ubuntu xenial-security main"
sudo apt update
sudo apt install libjasper1 libjasper-dev
只要输入./应用名称能运行就可以忽略sh: 1: appimagetool: not found文章来源:https://www.toymoban.com/news/detail-689289.html
./untitled
文章来源地址https://www.toymoban.com/news/detail-689289.html
到了这里,关于linuxdeployqt源码编译与打包的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!