新聞中心
寫了點(diǎn)QT界面程序,然而發(fā)現(xiàn)很難移植到其他沒有安裝Qt環(huán)境的電腦上運(yùn)行。查資料了解到,在windows上有windowsdeployqt程序,linux上有l(wèi)inuxdeployqt可以幫助我們快速打包。

平房網(wǎng)站制作公司哪家好,找創(chuàng)新互聯(lián)!從網(wǎng)頁設(shè)計(jì)、網(wǎng)站建設(shè)、微信開發(fā)、APP開發(fā)、響應(yīng)式網(wǎng)站建設(shè)等網(wǎng)站項(xiàng)目制作,到程序開發(fā),運(yùn)營維護(hù)。創(chuàng)新互聯(lián)自2013年起到現(xiàn)在10年的時間,我們擁有了豐富的建站經(jīng)驗(yàn)和運(yùn)維經(jīng)驗(yàn),來保證我們的工作的順利進(jìn)行。專注于網(wǎng)站建設(shè)就選創(chuàng)新互聯(lián)。
1. 配置Qt環(huán)境
首先,我們先把Qt環(huán)境配置好,在~/.bashrc中加入:
export PATH=/home/xl/Qt5.9.2/5.9.2/gcc_64/bin:$PATH export LD_LIBRARY_PATH=/home/xl/Qt5.9.2/5.9.2/gcc_64/lib:$LD_LIBRARY_PATH export QT_PLUGIN_PATH=/home/xl/Qt5.9.2/5.9.2/gcc_64/plugins:$QT_PLUGIN_PATH export QML2_IMPORT_PATH=/home/xl/Qt5.9.2/5.9.2/gcc_64/qml:$QML2_IMPORT_PATH
其中/home/xl/Qt5.9.2/5.9.2/目錄要根據(jù)自己電腦上安裝的Qt路徑進(jìn)行修改。
然后執(zhí)行sourec ~/.bashrc使配置生效。
2. 編譯linuxdeployqt
項(xiàng)目地址: https://github.com/probonopd/linuxdeployqt.git 。
雖然有放出編譯好的包,但是由于我使用的是ubuntu18, 系統(tǒng)版本過高,因此還是選擇編譯代碼的方式。
為了避免編譯好的包運(yùn)行時檢測到我們的系統(tǒng)版本過高,不繼續(xù)執(zhí)行的問題,我們編譯前,將tools/linuxdeployqt/main.cpp中的下述代碼注釋掉:
// openSUSE Leap 15.0 uses glibc 2.26 and is used on OBS
/*if (strverscmp (glcv, "2.27") >= 0) { //注釋版本檢查
qInfo() << "ERROR: The host system is too new.";
qInfo() << "Please run on a system with a glibc version no newer than what comes with the oldest";
qInfo() << "currently still-supported mainstream distribution (xenial), which is glibc 2.23.";
qInfo() << "This is so that the resulting bundle will work on most still-supported Linux distributions.";
qInfo() << "For more information, please see";
qInfo() << "https://github.com/probonopd/linuxdeployqt/issues/340";
return 1;
}*/然后就可以使用cmake和make進(jìn)行編譯。生成好的可執(zhí)行程序是tools/linuxdeployqt/linuxdeployqt。
最后為了方便使用,可以將生成的可執(zhí)行程序拷貝到系統(tǒng)的/usr/local/bin/目錄。
3. 打包
將Qt編譯的好的程序拷貝到一個單獨(dú)的文件夾中。
然后執(zhí)行linuxdeployqt appname.
一般情況下會很順利的完成,當(dāng)前目錄下會有個Apprun,直接執(zhí)行它就可以。
但是有時候并不是那么順利,應(yīng)該是系統(tǒng)中還缺少相應(yīng)的庫。比如,我遇到的錯誤是:
ERROR: Could not start patchelf. ERROR: Make sure it is installed on your $PATH. ERROR: Error reading rpath with patchelf "libQt5Widgets.so" : "" ERROR: Error reading rpath with patchelf "libQt5Widgets.so" : ""
這個錯誤是表明缺少需要的pathchelf工具,直接安裝即可解決:
sudo apt install patchelf
然后又出現(xiàn)了下面這個錯誤:
ERROR: ldd outputLine: “l(fā)ibjasper.so.1 => not found”
ERROR: for binary: “/home/xl/Qt5.9.2/5.9.2/gcc_64/plugins/imageformats/libqjp2.so”
ERROR: Please ensure that all libraries can be found by ldd. Aborting.
這表明我們系統(tǒng)中是缺少了libqjp2.so這個庫的。其實(shí)很奇怪,本地明明是已經(jīng)可以跑起來了,為什么還缺少這個庫文件。但是解決方法很簡單,缺什么就裝什么:
sudo add-apt-repository "deb http://security.ubuntu.com/ubuntu xenial-security main" sudo apt update sudo apt install libjasper1 libjasper-dev
安裝完成之后,就順利打包了。
總結(jié)
以上所述是小編給大家介紹的解決Ubuntu下使用linuxdeployqt打包Qt程序問題,大家如有疑問可以留言,或者聯(lián)系站長。感謝親們支持?。?!
如果你覺得本文對你有幫助,歡迎轉(zhuǎn)載,煩請注明出處,謝謝!
成都網(wǎng)站建設(shè)選創(chuàng)新互聯(lián)(?:028-86922220),專業(yè)從事成都網(wǎng)站制作設(shè)計(jì),高端小程序APP定制開發(fā),成都網(wǎng)絡(luò)營銷推廣等一站式服務(wù)。
名稱欄目:解決Ubuntu下使用linuxdeployqt打包Qt程序問題
網(wǎng)址分享:http://www.dlmjj.cn/article/djsieij.html


咨詢
建站咨詢
