Discuz! Board

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 2637|回复: 0
打印 上一主题 下一主题

Linux下Qt程序的打包发布

[复制链接]

1228

主题

1998

帖子

7596

积分

认证用户组

Rank: 5Rank: 5

积分
7596
跳转到指定楼层
楼主
发表于 2018-4-11 11:15:48 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
本帖最后由 Qter 于 2018-4-13 16:18 编辑

https://blog.csdn.net/flfihpv259/article/details/71407020

程序以test为例:

  • QtCreate使用Release版本编译

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

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

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

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


  1. #!/bin/sh  


  2. exe="test" #发布的程序名称  
  3. des="/home/hejianglin/QtProject/build-test-Desktop-Release/ReleaseTest" #你的路径  

  4. deplist=$(ldd $exe | awk  '{if (match($3,"/")){ printf("%s "),$3 } }')  
  5. cp $deplist $des
复制代码
说明:exe :要发布的程序名称 des:指定复制的路径
把此文件命名为: getdep.sh 放到build-test-Desktop_Qt_5_8_0_GCC_64bit-Release目录下
  1. chmod +x getdep.sh
复制代码
./getdep.sh 执行




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

  1. #!/bin/sh

  2. appname=`basename $0 | sed s,\.sh$,,`

  3. dirname=`dirname $0`
  4. tmp="${dirname#?}"

  5. if [ "${dirname%$tmp}" != "/" ]; then
  6. dirname=$PWD/$dirname
  7. fi
  8. LD_LIBRARY_PATH=$dirname
  9. export LD_LIBRARY_PATH
  10. $dirname/$appname "$@"
复制代码
  1. chmod +x test.sh
复制代码
ReleaseTest目录拷贝到其它电脑上运行


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


运行时还会提示其他的动态库文件缺失,根据提示再次拷贝相应的文件

可以在开发环境中使用ldd命令查看执行程序依赖的Qt动态库文件,ldd qtest | grep libQt,打包拷贝。

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

解决:在执行程序所在的当前路径下创建子目录,并从开发环境中Qt安装目录下的plugins子目录中拷贝动态库文件

mkdir platforms

scp 开发环境:/path_to_Qt/plugins/platforms/libqxcb.so platforms/
scp /home/hechengjin/Qt5.8.0/5.8/gcc_64/plugins/platforms/libqxcb.so platforms/
重要!!! 根据ldd libqxcb.so的输出拷贝需要的几个库文件,如libQt5DBus.so.5 libQt5XcbQpa.so.5,放在与执行程序相同的路径下


报错
QXcbIntegration: Cannot create platform OpenGL context, neither GLX nor EGL are enabled
QXcbIntegration: Cannot create platform offscreen surface, neither GLX nor EGL are enabled
failed to acquire GL context to resolve capabilities, using defaults..
QXcbConnection: XCB error: 147 (Unknown), sequence: 171, resource id: 0, major code: 140 (Unknown), minor code: 20
QXcbIntegration: Cannot create platform OpenGL context, neither GLX nor EGL are enabled
Failed to create OpenGL context for format QSurfaceFormat(version 2.0, options QFlags(), depthBufferSize 24, redBufferSize -1, greenBufferSize -1, blueBufferSize -1, alphaBufferSize -1, stencilBufferSize 8, samples -1, swapBehavior 2, swapInterval 1, profile  0)

解决:从开发环境中拷贝所需的glx/egl插件
mkdir xcbglintegrations

scp 开发环境:/path_to_Qt/plugins/xcbglintegrations/libqxcb-egl-integration.so xcbglintegrations

scp 开发环境:/path_to_Qt/plugins/xcbglintegrations/libqxcb-glx-integration.so xcbglintegrations

scp /home/hechengjin/Qt5.8.0/5.8/gcc_64/plugins/xcbglintegrations/libqxcb-egl-integration.so xcbglintegrations
scp /home/hechengjin/Qt5.8.0/5.8/gcc_64/plugins/xcbglintegrations/libqxcb-glx-integration.so xcbglintegrations

https://blog.csdn.net/justkk/article/details/52921899

new
getdep.sh
  1. exe="test" #发布的程序名称
  2. xcb="test/platforms/libqxcb.so"
  3. des="/home/hechengjin/code/tools/build-test-Desktop_Qt_5_8_0_GCC_64bit-Release/test" #你的路径

  4. deplist=$(ldd $exe  | awk  '{if (match($3,"/")){ printf("%s "),$3 } }')
  5. deplist2=$(ldd $xcb | awk  '{if (match($3,"/")){ printf("%s "),$3 } }')
  6. cp $deplist $des
  7. cp $deplist2 $des
复制代码
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|firemail ( 粤ICP备15085507号-1 )

GMT+8, 2024-5-15 05:54 , Processed in 0.099152 second(s), 19 queries .

Powered by Discuz! X3

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表