溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

如何在Ubuntu中使用linuxdeployqt對Qt程序進(jìn)行打包

發(fā)布時間:2021-03-24 17:09:23 來源:億速云 閱讀:1063 作者:Leah 欄目:服務(wù)器

這篇文章將為大家詳細(xì)講解有關(guān)如何在Ubuntu中使用linuxdeployqt對Qt程序進(jìn)行打包,文章內(nèi)容質(zhì)量較高,因此小編分享給大家做個參考,希望大家閱讀完這篇文章后對相關(guā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

項目地址: 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: "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這個庫的。其實很奇怪,本地明明是已經(jīng)可以跑起來了,為什么還缺少這個庫文件。但是解決方法很簡單,缺什么就裝什么:

sudo add-apt-repository "deb http://security.ubuntu.com/ubuntu xenial-security main"
sudo apt update
sudo apt install libjasper1 libjasper-dev

關(guān)于如何在Ubuntu中使用linuxdeployqt對Qt程序進(jìn)行打包就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,可以學(xué)到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI