|
本帖最后由 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打印出来的依赖库复制到指定路径:
- #!/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
复制代码 说明:exe :要发布的程序名称 des:指定复制的路径
把此文件命名为: getdep.sh 放到build-test-Desktop_Qt_5_8_0_GCC_64bit-Release目录下
./getdep.sh 执行
5. 编写.sh文档 并将它放在与ReleaseTest目录下(.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 "$@"
复制代码 把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- exe="test" #发布的程序名称
- xcb="test/platforms/libqxcb.so"
- des="/home/hechengjin/code/tools/build-test-Desktop_Qt_5_8_0_GCC_64bit-Release/test" #你的路径
- deplist=$(ldd $exe | awk '{if (match($3,"/")){ printf("%s "),$3 } }')
- deplist2=$(ldd $xcb | awk '{if (match($3,"/")){ printf("%s "),$3 } }')
- cp $deplist $des
- cp $deplist2 $des
复制代码 |
|