linuxdeployqt-linux下Qt打包工具

2023-03-10 13:12:34 浏览数 (2)

linuxdeployqt

简介

基于Windows-Qt 发布的打包工具windeployqt,主要打包Qt相关依赖库,但是在linux,qt官方并未发布对应的打包版本。在github中,有人开源了这个版本linuxdeployqt,之前一直知道但是没怎么用,最近因为要打包对应工程,又拿出研究了一下。

  • Windows介绍
代码语言:javascript复制
The Windows deployment tool windeployqt is designed to automate the process of creating a deployable folder containing the Qt-related dependencies (libraries, QML imports, plugins, and translations) required to run the application from that folder. It creates a sandbox for Universal Windows Platform (UWP) or an installation tree for Windows desktop applications, which can be easily bundled into an installation package.

看一下Windows命令。

代码语言:javascript复制
Qt Deploy Tool 6.0.3

The simplest way to use windeployqt is to add the bin directory of your Qt
installation (e.g. <QT_DIRbin>) to the PATH variable and then run:
  windeployqt <path-to-app-binary>
If ICU, etc. are not in the bin directory, they need to be in the PATH
variable. If your application uses Qt Quick, run:
  windeployqt --qmldir <path-to-app-qml-files> <path-to-app-binary>

Options:
  -?, -h, --help              Displays help on commandline options.
  --help-all                  Displays help including Qt specific options.
  -v, --version               Displays version information.
  --dir <directory>           Use directory instead of binary directory.
  --qmake <path>              Use specified qmake instead of qmake from PATH.
  --libdir <path>             Copy libraries to path.
  --plugindir <path>          Copy plugins to path.
  --debug                     Assume debug binaries.
  --release                   Assume release binaries.
  --pdb                       Deploy .pdb files (MSVC).
  --force                     Force updating files.
  --dry-run                   Simulation mode. Behave normally, but do not
                              copy/update any files.
  --no-patchqt                Do not patch the Qt6Core library.
  --ignore-library-errors     Ignore errors when libraries cannot be found.
  --no-plugins                Skip plugin deployment.
  --no-libraries              Skip library deployment.
  --qmldir <directory>        Scan for QML-imports starting from directory.
  --qmlimport <directory>     Add the given path to the QML module search
                              locations.
  --no-quick-import           Skip deployment of Qt Quick imports.
  --translations <languages>  A comma-separated list of languages to deploy
                              (de,fi).
  --no-translations           Skip deployment of translations.
  --no-system-d3d-compiler    Skip deployment of the system D3D compiler.
  --compiler-runtime          Deploy compiler runtime (Desktop only).
  --no-virtualkeyboard        Disable deployment of the Virtual Keyboard.
  --no-compiler-runtime       Do not deploy compiler runtime (Desktop only).
  --json                      Print to stdout in JSON format.
  --no-opengl-sw              Do not deploy the software rasterizer library.
  --list <option>             Print only the names of the files copied.
                              Available options:
                               source:   absolute path of the source files
                               target:   absolute path of the target files
                               relative: paths of the target files, relative
                                         to the target directory
                               mapping:  outputs the source and the relative
                                         target, suitable for use within an
                                         Appx mapping file
  --verbose <level>           Verbose level (0-2).

Qt libraries can be added by passing their name (-xml) or removed by passing
the name prepended by --no- (--no-xml). Available libraries:
bluetooth concurrent core declarative designer designercomponents gamepad gui
qthelp multimedia multimediawidgets multimediaquick network nfc opengl
openglwidgets positioning printsupport qml qmltooling quick quickparticles
quickwidgets script scripttools sensors serialport sql svg svgwidgets test
websockets widgets winextras xml webenginecore webengine webenginewidgets 3dcore
3drenderer 3dquick 3dquickrenderer 3dinput 3danimation 3dextras geoservices
webchannel texttospeech serialbus webview

Arguments:
  [files]                     Binaries or directory containing the binary.
  • linux介绍
代码语言:javascript复制
This Linux Deployment Tool, linuxdeployqt, takes an application as input and makes it self-contained by copying in the resources that the application uses (like libraries, graphics, and plugins) into a bundle. The resulting bundle can be distributed as an AppDir or as an AppImage to users, or can be put into cross-distribution packages. It can be used as part of the build process to deploy applications written in C, C  , and other compiled languages with systems like CMake, qmake, and make. When used on Qt-based applications, it can bundle a specific minimal subset of Qt required to run the application.

帮助文档:

代码语言:javascript复制
linuxdeployqt 7 (commit d41e234), build <local dev build> built on 2021-05-31 09:46:09 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.
   -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.
   -executable=<path>       : Let the given executable 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.
   -qmldir=<path>           : Scan for QML imports in the given path.
   -qmlimport=<path>        : Add the given path to QML module search locations.
   -show-exclude-libs       : Print exclude libraries list.
   -verbose=<0-3>           : 0 = no output, 1 = error/warning (default),
                              2 = normal, 3 = debug.
   -updateinformation=<update string>        : Embed update information STRING; if zsyncmake is installed, generate zsync file
   -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.

编译

下载

代码语言:javascript复制
git clone https://github.com/probonopd/linuxdeployqt.git -b 7 --depth 1

博主下载了 tag 7

编译-安装

代码语言:javascript复制
cd linuxdeployqt
mkdir build
cd build
qmake ../linuxdeployqt.pro
make -j
sudo make install
#安装路径:/opt/Qt/Qt5.9.5/5.9.5/gcc_64/bin/linuxdeployqt 。Qt默认安装路径。
#ln -s /opt/Qt/Qt5.9.5/5.9.5/gcc_64/bin/linuxdeployqt /usr/bin/linuxdeployqt 配置为全局可执行程序

其他相关库下载:

  • patchelf
代码语言:javascript复制
#动态链接库工具(链接、重定向)
wget https://nixos.org/releases/patchelf/patchelf-0.9/patchelf-0.9.tar.bz2
tar xf patchelf-0.9.tar.bz2
( cd patchelf-0.9/ && ./configure  && make && sudo make install )
  • appimagetool
代码语言:javascript复制
#注意:根据对应平台下载(桌面-app生成工具)
sudo wget -c "https://github.com/AppImage/AppImageKit/releases/download/continuous/appimagetool-x86_64.AppImage" -O /usr/local/bin/appimagetool
sudo chmod a x /usr/local/bin/appimagetool

测试

linuxdeployqt配置为全局可执行程序后。开始测试:

代码语言:javascript复制
linuxdeployqt ./xxxx -verbose=2 -appimage
#-verbose=<0-3> : 0 = no output, 1 = error/warning (default),2 = normal, 3 = debug.
#-appimage      : Create an AppImage (implies -bundle-non-qt-libs).

输出:

代码语言:javascript复制
Log: Creating  "xxxxxxxxxx/translations/qt_tterns_uk.qm" ...
Log: "appimagetool -v 'xxxxxxxxxx' -n -g"
appimagetool, continuous build (commit 8bbf694), build <local dev build> built on 2020-12-31 11:48:33 UTC
NOTE: Using the output of 'git rev-parse --short HEAD' as the version:
      2eb7984
      Please set the $VERSION environment variable if this is not intended
Desktop file: xxxxxxxxxxx/default.desktop
Categories entry not found in desktop file
.desktop file is missing a Categories= key
Log: ret 256
Log: WEXITSTATUS(ret) 1
  • 错误
代码语言:javascript复制
linuxdeployqt ./RdpClient
linuxdeployqt 7 (commit d41e234), build <local dev build> built on 2021-05-31 09:46:09 UTC
FHS-like mode with PREFIX, fhsPrefix: "/../.."
QDir::exists: Empty or null file name
ERROR: Error: Could not find app-binary ""

安装包

安装包路径

下载完之后,给与可执行权限chmod a x linuxdeployqt-continuous-x86_64.AppImage,全局环境变量配置mv linuxdeployqt-continuous-x86_64.AppImage /usr/bin ,或者按照上述安装路径,mv linuxdeployqt-continuous-x86_64.AppImagelinuxdeployqt /opt/Qt/Qt5.9.5/gcc/bin/linuxdeployqt

注意事项

生成文件:

代码语言:javascript复制
AppRun  default.desktop  default.png  description-pak  doc  doc-pak  lib  Makefile    plugins  qt.conf  RdpClient  translations

实际使用过程中:

platformsplugins 应该位于同级目录。如下述。

代码语言:javascript复制
AppRun  default.desktop  default.png  description-pak  doc  doc-pak  lib  Makefile  platforms  plugins  qt.conf  RdpClient  translations

而生成的目录路径如下:

代码语言:javascript复制
├── plugins
│   ├── iconengines
│   ├── imageformats
│   ├── platforminputcontexts
│   ├── platforms
│   └── xcbglintegrations

需要做一个拷贝动作;mv luginsplatforms ./

然后在执行相关打包工作。

0 人点赞