网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

Ubuntu下如何使用linuxdeployqt打包Qt程序

本篇内容介绍了“Ubuntu下如何使用linuxdeployqt打包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, 系统版本过高,因此还是选择编译代码的方式。

为了避免编译好的包运行时检测到我们的系统版本过高,不继续执行的问题,我们编译前,将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编译的好的程序拷贝到一个单独的文件夹中。

 然后执行linuxdeployqt appname.

一般情况下会很顺利的完成,当前目录下会有个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工具,直接安装即可解决:

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

安装完成之后,就顺利打包了。

“Ubuntu下如何使用linuxdeployqt打包Qt程序”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注创新互联网站,小编将为大家输出更多高质量的实用文章!


网站名称:Ubuntu下如何使用linuxdeployqt打包Qt程序
当前URL:http://bjjierui.cn/article/ppcjji.html

其他资讯