这篇文章将为你们详尽讲解有关怎样在Ubuntu中使用linuxdeployqt对Qt程序进行打包,文章内容质量较高,因而小编分享给你们做个参考linux qt程序打包发布,希望你们阅读完这篇文章后对相关知识有一定的了解。
1.配置Qt环境
首先,我们先把Qt环境配置好,在~/.bashrc中加入:
export PATH=/home/xl/Qt5.9.2/5.9.2/gcc_64/bin:$PATH export LD_LIBRARY_PATH=/home/xl/Qt5.9.2/5.9.2/gcc_64/lib:$LD_LIBRARY_PATH export QT_PLUGIN_PATH=/home/xl/Qt5.9.2/5.9.2/gcc_64/plugins:$QT_PLUGIN_PATH export QML2_IMPORT_PATH=/home/xl/Qt5.9.2/5.9.2/gcc_64/qml:$QML2_IMPORT_PATH
其中/home/xl/Qt5.9.2/5.9.2/目录要按照自己笔记本上安装的Qt路径进行更改。
之后执行sourec~/.bashrc使配置生效。
2.编译linuxdeployqt
项目地址:。
其实有放出编译好的包,而且因为我使用的是Ubuntu18,系统版本过低,因而还是选择编译代码的形式。
为了防止编译好的包运行时检查到我们的系统版本过低,不继续执行的问题,我们编译前linux虚拟机,将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; }*/
之后就可以使用cmake和make进行编译。生成好的可执行程序是tools/linuxdeployqt/linuxdeployqt。
最后为了便捷使用,可以将生成的可执行程序拷贝到系统的/usr/local/bin/目录。
3.打包
将Qt编译的好的程序拷贝到一个单独的文件夹中。
之后执行linuxdeployqtappname.
通常情况下会很顺利的完成,当前目录下会有个Apprun,直接执行它就可以。
并且有时侯并不是这么顺利,应当是系统中还缺乏相应的库。例如,我碰到的错误是:
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工具,直接安装即可解决:
sudoaptinstallpatchelf
之后又出现了下边这个错误:
ERROR:lddoutputLine:"libjasper.so.1=>notfound"
ERROR:forbinary:"/home/xl/Qt5.9.2/5.9.2/gcc_64/plugins/imageformats/libqjp2.so"
ERROR:Pleaseensurethatalllibrariescanbefoundbyldd.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
关于怎样在Ubuntu中使用linuxdeployqt对Qt程序进行打包就分享到这儿了,希望以上内容可以对你们有一定的帮助linux公社,可以学到更多知识。假如认为文章不错linux qt程序打包发布,可以把它分享出去让更多的人听到。