在Linux下打包Qt程序

 在windows和mac中qt有自己的依赖打包程序,分别是windeployqt和macdeployqt,但却没有自带的linuxdeployqt,需要下载三方程序使用。

下载linuxdeployqt:Releases · probonopd/linuxdeployqt · GitHubMakes Linux applications self-contained by copying in the libraries and plugins that the application uses, and optionally generates an AppImage. Can be used for Qt and other applications - Releases · probonopd/linuxdeployqticon-default.png?t=N7T8https://github.com/probonopd/linuxdeployqt/releases

将最新版程序linuxdeployqt-x86_64.AppImage下载后改名为linuxdeployqt以方便调用。

将改名后的linuxdeployqt设置权限。

将修改好的文件放至系统环境目录/usr/local/bin下。

命令行内容如下:

$ chmod a+x linuxdeployqt-x86_64.AppImage
$ mv linuxdeployqt-x86_64.AppImage linuxdeployqt
$ mv linuxdeployqt /usr/local/bin 

调用linuxdeployqt –version测试程序是否安装成功

修改系统环境文件~/.bashrc增加自己的qt安装目录路径

export PATH=/home/chinaedu/Qt/5.15.2/gcc_64/bin:$PATH
export LIB_PATH=/home/chinaedu/Qt/5.15.2/gcc_64/lib:$LIB_PATH
export PLUGIN_PATH=/home/chinaedu/Qt/5.15.2/gcc_64/plugins:$PLUGIN_PATH
export QML2_PATH=/home/chinaedu/Qt/5.15.2/gcc_64/qml:$QML2_PATH

Qt的安装路径位置可以通过以下命令获取:whereis qt

使用qmake -v测试环境变理查看qmake版本是否正确。

可执行linuxdeployqt程序查看参数使用方法:

linuxdeployqt  (commit 8cb9438), build 67 built on 2024-07-09 18:22:04 UTC

Usage: linuxdeployqt <app-binary|desktop file> [options]

Options:

   -always-overwrite                : Copy files even if the target file exists.

覆盖已存在目标依赖文件

   -appimage                : Create an AppImage (implies -bundle-non-qt-libs).

创建集成所有依赖项文件

   -bundle-non-qt-libs      : Also bundle non-core, non-Qt libraries.

捆绑非核心和非QT库

   -exclude-libs=<list>     : List of libraries which should be excluded,

                              separated by comma.

排除指定列表库集成,用逗号分隔

   -ignore-glob=<glob>      : Glob pattern relative to appdir to ignore when

                              searching for libraries.

用于指定相对于应用程序目录的 glob 模式,该模式用于在搜索库时忽略匹配的文件或目录。

   -executable=<path>       : Let the given executable use the deployed libraries

                              Too

让指定的程序也使用依赖库

   -executable-dir=<path>   : Let all the executables in the folder (recursive) use

                              the deployed libraries too

让所有在指定目录(递归)中的程序使用依赖库

   -extra-plugins=<list>    : List of extra plugins which should be deployed,

                              separated by comma.

部署额外的插件集成,用逗号分隔

   -no-copy-copyright-files : Skip deployment of copyright files.

跳过复制版权文件

   -no-plugins              : Skip plugin deployment.

跳过插件部署

   -no-strip                : Don't run 'strip' on the binaries.

跳过执行二进制程序中的不必要的信息(如调试)

   -no-translations         : Skip deployment of translations.

跳过翻译部署

   -qmake=<path>            : The qmake executable to use.

单独设置生成依赖的qmake路径

   -qmldir=<path>           : Scan for QML imports in the given path.

单独设置生成依赖的qml路径

   -qmlimport=<path>        : Add the given path to QML module search locations.

单独设置生成依赖的qml导入路径

   -show-exclude-libs       : Print exclude libraries list.

显示排除的库列表

   -verbose=<0-3>           : 0 = no output, 1 = error/warning (default),

                              2 = normal, 3 = debug.

输出附加信息模式:0.无输出,1.错误/警告(默认)2.正常,3.调试

   -updateinformation=<update string>        : Embed update information STRING; if zsyncmake is installed, generate zsync file

嵌入更新信息字符串,如果安装了zsyncmake则生成zsync文件

   -qtlibinfix=<infix>          : Adapt the .so search if your Qt distribution has infix.

调整so文件搜索Qt发布是否有中缀

   -version                 : Print version statement and exit.

显示输出版本信息就退出

linuxdeployqt takes an application as input and makes it

self-contained by copying in the Qt libraries and plugins that

the application uses.

By default it deploys the Qt instance that qmake on the $PATH points to.

The '-qmake' option can be used to point to the qmake executable

to be used instead.

Plugins related to a Qt library are copied in with the library.

See the "Deploying Applications on Linux" topic in the

documentation for more information about deployment on Linux.

如需安装appimagetools可在此处下载:

Releases · AppImage/AppImageKit · GitHubPackage desktop applications as AppImages that run on common Linux-based operating systems, such as RHEL, CentOS, openSUSE, SLED, Ubuntu, Fedora, debian and derivatives. Join #AppImage on irc.libera.chat - Releases · AppImage/AppImageKiticon-default.png?t=N7T8https://github.com/AppImage/AppImageKit/releases

将文件同样放至/usr/local/bin/中改名为appimagetool并设置权限

$ chmod a+x appimagetool-x86_64.AppImage
$ mv appimagetool-x86_64.AppImage appimagetool
$ mv appimagetool /usr/local/bin

打包拷贝依赖文件:

linuxdeployqt 程序文件名称 -appimage

打包后会生成default.desktop文件,如出现以下问题

Categories entry not found in desktop file
.desktop file is missing a Categories= key

修改default.desktop文件在最后一行加入Categories=Utility;Application;再重新打包。

如需修改图片设置default.png文件再打包即可。

打包后可创建[程序名称.bash]文件至同目录下用以自动设置环境变量并运行:

#!/bin/sh
me=`basename "$0"`
extension="${me##*.}"
filename="${me%.*}"
HERE="$(dirname "$(readlink -f "${0}")")"
export LD_LIBRARY_PATH="${HERE}"
export LD_LIBRARY_PATH="${HERE}"/lib:$LD_LIBRARY_PATH
export QT_PLUGIN_PATH="${HERE}"/plugins
export QT_QPA_PLATFORM_PLUGIN_PATH="${HERE}"/plugins/platforms
exec "${HERE}"/$filename

  • 10
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值