1. 程式人生 > >linux Qt程式打包(linuxdeployqt工具的使用)

linux Qt程式打包(linuxdeployqt工具的使用)

linux Qt程式打包(linuxdeployqt工具的使用)
官方提供的最新版本基於Qt5.8的,使用者可根據需要從原始碼編譯成本機版本來使用,具體操作過程如下:

工具
1.linuxdeployqt
依賴工具:
patchelf(必須)
appimagetool(可選)
2.Qt
確保機器已經安裝Qt

如果需要製作成單檔案程式,需要用到appimagetool,若不需要可不必下載

步驟
官網提供詳細步驟,這裡說下注意事項
下載下來的linuxdeployqt
1.1 (介面編譯)開啟QtCreator,開啟linuxdeployqt專案,直接構建即可,構建完成後在linuxdeployqt目錄下可找到編譯好的可執行檔案(linuxdeployqt)
1.2 (命令列)開啟終端,進入linuxdeployqt專案目錄,目錄結構如下:
ls
BUILDING.md LICENSE.LGPLv3 linuxdeployqt.pro shared
Dockerfile linuxdeployqt Makefile tests
LICENSE.GPLv3 linuxdeployqt.AppDir README.md

執行qmake之前先設定環境變數PATH

export PATH=~/Qt5.xx.x/5.x/gcc_xx/bin:$PATH
1
然後執行下

qmake -v 
1
檢視下當前使用的qmake是否為你需要的版本
設定完成後在linuxdeployqt專案目錄下直接執行qmake,然後再執行make即可,不需要make install

1.3 這樣編譯好後的可執行檔案位於linuxdeployqt/linuxdeployqt下,將其複製至系統程式可執行目錄下即可

sudo mv linuxdeployqt/linuxdeployqt /usr/local/bin
1
2.patchelf的編譯與安裝
操作步驟:

./configure
make
sudo make install (直接安裝至系統目錄即可)
關於 appimagetool 的安裝參照官網即可,直接用wget下載可能比較慢,可用迅雷或其他下載工具下載下來,然後拷貝至linux系統,具體操作步驟:

suco cp ppimagetool-x86_64.AppImage /usr/local/bin/appimagetool
sudo chmod a+x /usr/local/bin/appimagetool
1
2
使用方法
命令:
linuxdeployqt ~/path/to/project/application -appimage
appimage:若根據操作安裝了 appimagetool 時該引數有效,使用該引數可將你需要打包的程式打包成單個檔案;
其他相關引數

Options:
   -verbose=<0-3>      : 0 = no output, 1 = error/warning (default), 2 = normal, 3 = debug
   -no-plugins         : Skip plugin deployment
   -appimage           : Create an AppImage
   -no-strip           : Don't run 'strip' on the binaries
   -bundle-non-qt-libs : Also bundle non-core, non-Qt libraries
   -executable=<path>  : Let the given executable use the deployed libraries too
   -qmldir=<path>      : Scan for QML imports in the given path
   -always-overwrite   : Copy files even if the target file exists
linuxdeployqt takes an application as input and makes it
self-contained by copying in the Qt libraries and plugins that
the application uses.
1
2
3
4
5
6
7
8
9
10
11
12
官方文件

create by vacant. 轉載請註明
————————————————
版權宣告:本文為CSDN博主「vacantChan」的原創文章,遵循 CC 4.0 BY-SA 版權協議,轉載請附上原文出處連結及本宣告。
原文連結:https://blog.csdn.net/enaldick12/art