溫馨提示×

溫馨提示×

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

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

Ubuntu下如何使用linuxdeployqt打包Qt程序

發布時間:2022-10-22 11:24:19 來源:億速云 閱讀:634 作者:iii 欄目:服務器

本篇內容介紹了“Ubuntu下如何使用linuxdeployqt打包Qt程序”的有關知識,在實際案例的操作過程中,不少人都會遇到這樣的困境,接下來就讓小編帶領大家學習一下如何處理這些情況吧!希望大家仔細閱讀,能夠學有所成!

1. 配置qt環境

首先,我們先把qt環境配置好,在~/.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/目錄要根據自己電腦上安裝的qt路徑進行修改。

然后執行sourec ~/.bashrc使配置生效。

2. 編譯linuxdeployqt

雖然有放出編譯好的包,但是由于我使用的是ubuntu18, 系統版本過高,因此還是選擇編譯代碼的方式。

為了避免編譯好的包運行時檢測到我們的系統版本過高,不繼續執行的問題,我們編譯前,將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進行編譯。生成好的可執行程序是tools/linuxdeployqt/linuxdeployqt。

最后為了方便使用,可以將生成的可執行程序拷貝到系統的/usr/local/bin/目錄。

3. 打包

將qt編譯的好的程序拷貝到一個單獨的文件夾中。

 然后執行linuxdeployqt appname.

一般情況下會很順利的完成,當前目錄下會有個apprun,直接執行它就可以。

 但是有時候并不是那么順利,應該是系統中還缺少相應的庫。比如,我遇到的錯誤是:

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

然后又出現了下面這個錯誤:

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.

這表明我們系統中是缺少了libqjp2.so這個庫的。其實很奇怪,本地明明是已經可以跑起來了,為什么還缺少這個庫文件。但是解決方法很簡單,缺什么就裝什么:

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

安裝完成之后,就順利打包了。

“Ubuntu下如何使用linuxdeployqt打包Qt程序”的內容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業相關的知識可以關注億速云網站,小編將為大家輸出更多高質量的實用文章!

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女