寫了點(diǎn)Qt界面程序,然而發(fā)現(xiàn)很難移植到其他沒(méi)有安裝Qt環(huán)境的電腦上運(yùn)行。查資料了解到,在windows上有windowsdeployqt程序,linux上有l(wèi)inuxdeployqt可以幫助我們快速打包。
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)版本過(guò)高,因此還是選擇編譯代碼的方式。
為了避免編譯好的包運(yùn)行時(shí)檢測(cè)到我們的系統(tǒng)版本過(guò)高,不繼續(xù)執(zhí)行的問(wèn)題,我們編譯前,將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編譯的好的程序拷貝到一個(gè)單獨(dú)的文件夾中。
然后執(zhí)行linuxdeployqt appname.
一般情況下會(huì)很順利的完成,當(dāng)前目錄下會(huì)有個(gè)Apprun,直接執(zhí)行它就可以。
但是有時(shí)候并不是那么順利,應(yīng)該是系統(tǒng)中還缺少相應(yīng)的庫(kù)。比如,我遇到的錯(cuò)誤是:
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" : ""
這個(gè)錯(cuò)誤是表明缺少需要的pathchelf工具,直接安裝即可解決:
sudo apt install patchelf
然后又出現(xiàn)了下面這個(gè)錯(cuò)誤:
ERROR: ldd outputLine: "libjasper.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這個(gè)庫(kù)的。其實(shí)很奇怪,本地明明是已經(jīng)可以跑起來(lái)了,為什么還缺少這個(gè)庫(kù)文件。但是解決方法很簡(jiǎn)單,缺什么就裝什么:
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程序問(wèn)題,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
如果你覺(jué)得本文對(duì)你有幫助,歡迎轉(zhuǎn)載,煩請(qǐng)注明出處,謝謝!
標(biāo)簽:西寧 西藏 香港 淮北 濰坊 攀枝花 怒江 東營(yíng)
巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《解決Ubuntu下使用linuxdeployqt打包Qt程序問(wèn)題》,本文關(guān)鍵詞 解決,Ubuntu,下,使用,linuxdeployqt,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問(wèn)題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。