Linux环境中Qt程序的手工发布

Qt 5.7.0 编写的程序需要部署到一台没有安装Qt的目标机器上,程序采用C++与QML混合编程,QML做界面,C++写逻辑。

环境说明
开发环境Ubuntu 16.04.1 LTS
运行环境CentOS 7.2.1511

下面描述这个手工操作的发布过程。

1、在开发环境中采用Release方式编译程序,生成执行程序qtest
2、在目标环境中,从开发环境拷贝执行程序,并尝试执行./qtest
报错:error while loading shared libraries: libQt5Quick.so.5: cannot open shared object file: No such file or directory
解决:从开发环境中拷贝需要的动态库文件,放在与执行程序相同的路径下,并设置环境变量LD_LIBRARY_PATH
export LD_LIBRARY_PATH=.:$LD_LIBRARY_PATH
再次执行./qtest
3、运行时还会提示其他的动态库文件缺失,根据提示再次拷贝相应的文件

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

4、再次执行,报错

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/

重要!!! 根据ldd libqxcb.so的输出拷贝需要的几个库文件,如libQt5DBus.so.5 libQt5XcbQpa.so.5,放在与执行程序相同的路径下

5、再次执行,报错

qrc:/main.qml:1:1: module "QtQuick" is not installed
qrc:/main.qml:4:1: module "QtQuick.Controls" is not installed
qrc:/main.qml:3:1: module "QtQuick.Window" is not installed
qrc:/main.qml:2:1: module "QtQuick.Layouts" is not installed
...

解决:从开发环境中拷贝Qt安装目录下的qml子目录,并设置环境变量

scp -rp 开发环境:/path_to_Qt/qml ./

export QML2_IMPORT_PATH=./qml

6、再次执行,报错
qrc:/main.qml:4:1: plugin cannot be loaded for module "QtQuick.Controls": Cannot load library qml/QtQuick/Controls.2/libqtquickcontrols2plugin.so: (libQt5QuickTemplates2.so.5: cannot open shared object file: No such file or directory)
qrc:/main.qml:4:1: plugin cannot be loaded for module "QtQuick.Controls": Cannot load library qml/QtQuick/Controls.2/libqtquickcontrols2plugin.so: (libQt5QuickControls2.so.5: cannot open shared object file: No such file or directory)
qrc:/main.qml:3:1: plugin cannot be loaded for module "QtQuick.Controls": Cannot load library qml/QtQuick/Controls/libqtquickcontrolsplugin.so: (libQt5Widgets.so.5: cannot open shared object file: No such file or directory)

解决:根据提示,从开发环境拷贝缺失的动态库文件

7、再次执行,报错
qrc:/main.qml:14:5: QML Image: Error decoding: qrc:/png/1/back.jpg: Unsupported image format
解决:从开发环境中拷贝图像格式解析插件

mkdir imageformats

scp 开发环境:/path_to_Qt/plugins/imageformats/libqjpeg.so imageformats/

8、再次执行,报错
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

9、搞定


总结:

目标环境需要四类文件:

1、一组动态库文件,放在执行程序所在目录下

2、一组插件,放在执行程序所在目录下的子目录中

3、一个qml子目录

4、两个环境变量LD_LIBRARY_PATH QML2_IMPORT_PATH

评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值