版權聲明:本文爲博主原創文章,遵循 CC 4.0 BY-SA 版權協議,轉載請附上原文出處連接和本聲明。
本文連接:https://blog.csdn.net/u014746574/article/details/79288727
linux qt 程序打包發佈
1.linuxdeployqt 安裝
最簡單的方法直接下載編譯好的 linuxdeployqt-x86_64.AppImage文件,將其更名字爲linuxdeployqt,並chmod a+x,而後複製到 /usr/local/bin/。而後命令行輸入 linuxdelpoyqt –version,輸出linuxdeployqt 版本就安裝成功。
linuxdeployqt-x86_64.AppImage 下載地址,https://github.com/probonopd/linuxdeployqt/releaseshtml
點擊linuxdeployqt-x86_64.AppImage右鍵下載便可。linux
$ mv linuxdeployqt-x86_64.AppImage linuxdeployqt
$ mv ./linuxdeployqt /usr/local/bin
$ linuxdelpoyqt --version
linuxdeployqt 4 (commit 988d294), build 481 built on 2018-02-02 15:05:23 UTC
1
2
3
4
2.打包本身的程序
將本身的qt程序(如myQtApp)複製到一個目錄(如 qtTest),運行
1
$ linuxdeployqt ./myQtApp -appimage
1
3.在ubuntu 中添加qt 應用程序圖標
修改qt 目錄下的desktop 文件。能夠按照ubuntu 官方提示修改。
ubuntu desktop文件使用git
#-- 全局安裝(全部用戶可用),將xxx.desktop 複製到/usr/share/applications
#-- 當前用戶可用, 將xxx.desktop 複製到 ~/.local/share/applications 目錄便可
#--appName.desktop
[Desktop Entry]
Version=1.0 #app的版本
Name=myQtApp #app的名字
Comment= this app use for xxx #說明信息
Exec=/path/to/your/QtApp/myQtApp #app的執行路徑,絕對路徑
Icon=/path/to/your/app_icon/myQtApp.png #icon 路徑,絕對路徑
Terminal=false #是否在終端啓動,效果本身試一下就知道了
Type=Application
Categories=Utility;Application;
1
2
3
4
5
6
7
8
9
10
11
12
四、關於qt.conf
這個文件指定了qt 程序的運行環境。
引用qt說明的原話:
The qt.conf file can be used to override the hard-coded paths that are compiled into the Qt library. These paths are accessible using the QLibraryInfo class. Without qt.conf, the functions in QLibraryInfo return these hard-coded paths; otherwise they return the paths as specified in qt.conf.
即咱們能夠使用qt.conf 指定qt程序的運行路徑和庫路徑。
The file should have a Paths group which contains the entries that correspond to each value of the QLibraryInfo::LibraryLocation enum. See the QLibraryInfo documentation for details on the meaning of the various locations.
這個文件應該要包含QLibraryInfo::LibraryLocation enum,如如下內容github
Entry Default Value
Prefix 程序運行的路徑,一下全部的路勁都是相對於這個路徑
Libraries 程序的庫庫路勁,linuxdeployqt會自動再這個目錄生成./lib,並將須要的庫拷貝過來
… …
主要有這幾個,多餘的能夠上qt幫助文檔ubuntu
# Generated by linuxdeployqt
# https://github.com/probonopd/linuxdeployqt/
[Paths]
Prefix = ./ #程序的運行路勁
Libraries = ./lib #程序的庫路徑
Plugins = ./plugins #插件路徑
1
2
3
4
5
6
參考:http://doc.qt.io/qt-5/qt-conf.htmlapp
5.補充
雖然linuxdepoyqt能夠幫咱們解決多數狀況下庫的依賴問題,可是也有的時候不能完整解決。這個時候就須要咱們本身複製所依賴的庫。
提供一個腳本,複製依賴庫,複製如下代碼,將其保存成爲 copylib.shide
#!/bin/sh
bin=$1 #發佈的程序名稱 ui
desDir="./lib" #你的路徑 this
if [ ! -d $desDir ];then
#echo "makedir $desDir"
mkdir $desDir
fi
libList=$(ldd $bin | awk '{if (match($3,"/")){ printf("%s "),$3 } }')
cp $libList $desDir
1
2
3
4
5
6
7
8
9
10
11
命令行 運行.net
chmod a+x ./copylib.sh ./copylib.sh ./myapp 1 2 就能夠複製所須要的庫到當前目錄下的 ./lib 文件夾中 一般狀況下,結合linuxdelpoy 和 copylib.sh 能夠解決Linux 下 qt 程序的庫依賴問題 ———————————————— 版權聲明:本文爲CSDN博主「zhangjun0703」的原創文章,遵循 CC 4.0 BY-SA 版權協議,轉載請附上原文出處連接及本聲明。 原文連接:https://blog.csdn.net/u014746574/article/details/79288727