Linux 下qt 程序打包发布(使用linuxdelpoyqt ,shell 脚本)

版权声明:本文为博主原创文章,遵循 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