這篇文章將為大家詳細講解有關如何在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
項目地址: https://github.com/probonopd/linuxdeployqt.git 。
雖然有放出編譯好的包,但是由于我使用的是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程序進行打包就分享到這里了,希望以上內容可以對大家有一定的幫助,可以學到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。