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
————————————————
版權聲明:本文為CSDN博主「justkk」的原創文章,遵循CC 4.0 BY-SA版權協議,轉載請附上原文出處鏈接及本聲明。
原文鏈接:https://blog.csdn.net/justkk/article/details/52921899
總結
以上是生活随笔為你收集整理的Linux环境中Qt程序的手工发布的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: NVIDIA实锤:2年前的安培显卡性能依
- 下一篇: linux 其他常用命令