• 企业400电话
  • 微网小程序
  • AI电话机器人
  • 电商代运营
  • 全 部 栏 目

    企业400电话 网络优化推广 AI电话机器人 呼叫中心 网站建设 商标✡知产 微网小程序 电商运营 彩铃•短信 增值拓展业务
    解决Ubuntu下使用linuxdeployqt打包Qt程序问题

    写了点Qt界面程序,然而发现很难移植到其他没有安装Qt环境的电脑上运行。查资料了解到,在windows上有windowsdeployqt程序,linux上有linuxdeployqt可以帮助我们快速打包。

    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

    项目地址: https://github.com/probonopd/linuxdeployqt.git 。

     虽然有放出编译好的包,但是由于我使用的是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程序问题,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对脚本之家网站的支持!
    如果你觉得本文对你有帮助,欢迎转载,烦请注明出处,谢谢!

    上一篇:docker+daocloud实现前端项目自动构建部署
    下一篇:树莓派 msmtp和mutt 的安装和配置教程
  • 相关文章
  • 

    © 2016-2020 巨人网络通讯

    时间:9:00-21:00 (节假日不休)

    地址:江苏信息产业基地11号楼四层

    《增值电信业务经营许可证》 苏B2-20120278

    解决Ubuntu下使用linuxdeployqt打包Qt程序问题 解决,Ubuntu,下,使用,linuxdeployqt,