Linux下Qt程序的打包发布

转载地址–Linux下Qt程序的打包发布 
以下是转载内容—>

程序以test为例:

  1. QtCreate使用Release版本编译

  2. 从可运行程序的文件中拿出可执行文件,例:test

  3. 终端下使用ldd命令查看需要的连接库,例:ldd test

    (补充,再使用ldd时,如果将库拷贝到某目录下了,最好把该目录加到环境变量export LD_LIBRARY_PATH=./path中去,这样ldd才不会出漏)

  4. 把ldd查询到的所有需要的库导出 
    这里提供一个脚本将ldd打印出来的依赖库复制到指定路径:

    
    #!/bin/sh  
    
    
    exe="test" #发布的程序名称  
    des="/home/hejianglin/QtProject/build-test-Desktop-Release/ReleaseTest" #你的路径  
    
    deplist=$(ldd $exe | awk  '{if (match($3,"/")){ printf("%s "),$3 } }')  
    cp $deplist $des  
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10

    说明:exe :要发布的程序名称 des:指定复制的路径

  5. 编写.sh文档 并将它放在与步骤4同一目录下(.sh文件命名必须与可执行文件名字一样例:可执行文件名 test, .sh 文件名为 test.sh) 
    .sh文件代码如下:

    
    #!/bin/sh
    
    appname=`basename $0 | sed s,\.sh$,,`
    
    dirname=`dirname $0`
    tmp="${dirname#?}"
    
    if [ "${dirname%$tmp}" != "/" ]; then
    dirname=$PWD/$dirname
    fi
    LD_LIBRARY_PATH=$dirname
    export LD_LIBRARY_PATH
    $dirname/$appname "$@"
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
  6. 执行这个.sh文件: 
    可能因为不行执行需更改权限:

    chmod +x test.sh
    • 1

Ok!大功告成,将这个文件复制到其他电脑上就可以运行了。

注: 
Linux 版本:Ubuntu 14.04 LTS 
Qt:5.2.1

参考地址:http://doc.qt.io/qt-5/linux-deployment.html

<—–以上是转载内容


上述处理后,如果运行时提示缺少xcb等,如下

This application failed to start because it could not find or load the Qt platfo
rm plugin "xcb".                                                                

Available platform plugins are: kms, linuxfb, minimal, minimalegl, offscreen, xc
b.                  
  • 1
  • 2
  • 3
  • 4
  • 5

官方说明

All Qt GUI applications require a plugin that implements the Qt Platform Abstraction (QPA) layer in Qt 5. For Linux/X11, the name of the platform plugin is libqxcb.so. This file must be located within a specific subdirectory (by default, platforms) under your distribution directory.

还缺少QT的QPA插件,拷贝相应插件到应用程序目录,注,连同目录名一块拷贝。如应用程序在

path/example.exe
  • 1

插件放在

path/platforms/libqxcb.so
  • 1

运行还是提示缺XCB,那可能是XCB插件的依赖有问题,在目标平台使用LDD,如下查看发现还有一堆依赖没有。

root@NanoPi2:/home/fa/Desktop/deploy1# ldd platforms/libqxcb.so | grep "not foun
d"                                                                              
        libxcb-render-util.so.0 => not found                                    
        libxcb-image.so.0 => not found                                          
        libxcb-icccm.so.4 => not found                                          
        libxcb-randr.so.0 => not found                                          
        libxcb-keysyms.so.1 => not found                                        
        libxcb-xkb.so.1 => not found                                            
        libxkbcommon-x11.so.0 => not found                                      
        libQt5DBus.so.5 => not found   
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

拷贝过去。如果明明以经拷贝到当前目录了,ldd还显示not found,那要把当前目录加到环境变量下再ldd就不会出错了。说明ldd也是寻找系统库里的,不会寻找当前目录。

要完整显示qt界面最好把qt5/plugins全部拷贝过去。不然用了qss的可能无法显示。

root@NanoPi2:/home/fa/Desktop/deploy1# ls /mnt/usr/lib/arm-linux-gnueabihf/qt5/
bin/     imports/ libexec/ mkspecs/ plugins/ qml/ 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值