linuxdeployqt

linuxdeployqt是一个在Linux下为Qt应用部署的工具,将应用程序作为输入,并将复制的自包含的Qt库和插件和应用程序捆成一束。这可以使用fpm将跨平台的deb和rpm包转化为AppImage

与macdeployqt的差异

这个工具在概念上基于Qt工具包中的的Mac部署工具,macdeployqt,但是在逻辑上进行了略微的调整,加入了Linux所需的其他工具。

  • 代替macOS的.app包,这会为Linux生成一个AppDir
  • 代替macOS的.dmg映像文件,这会产生一个Linux的AppImage,与dmg非常相似,但会直接执行包含的应用程序,而不是只打开一个桌面窗口,选择应用的启动位置(MacOS用户应该明白讲的是什么,译者注)

已知的问题

可能还不能完全正常工作. 有关已知问题,参见GitHub问题。请仔细使用,以输出最详细日志模式运行,提交issues并pull requests。我们对您的帮助表示感谢。

安装

请从Releases页面下载 linuxdeployqt-x86_64.AppImage 并且运行chmod a + x。如果您想从源码编译生成 linuxdeployqt,请参阅BUILDING.md

用法

用法:linuxdeployqt app-binary [options]

参数:
   -verbose = <0-3>:0 = 无输出,1 = 错误/警告(默认),2 = 正常,3 = debug
   -no-plugins:忽略部署插件
   -appimage:创建一个AppImage
   -no-strip:不在二进制文件上运行“strip”
   -bundle-non-qt-libs:集成非核心、非Qt的库
   -executable = <path>:让给定的可执行文件也使用已部署的库
   -qmldir = <path>:扫描QML导入用来从给定目录中捆绑,使用Qt的qmlimportscanner
   -always-overwrite:即使目标文件存在,也可以复制文件
   -qmake = <path>:使用qmake的可执行文件
   -no-translations:忽略部署翻译文件

linuxdeployqt将一个self-contained(自包含)应用程序作为标的并使之生效
通过在Qt库和插件中复制应用程序使用。

最简单的例子

鉴于AppImage应该提供一个快捷方式,linuxdeployqt可以使用它来确定构建的参数。

linuxdeployqt ./path/to/appdir/usr/share/application_name.desktop

desktop 指定要运行的可执行文件(带有EXEC =),应用程序的名称和图标。 请参阅桌面文件规范

有关更详细的示例,请参阅下面的“使用Linuxdeployqt与Travis CI”。

检查库包含

在Qt Creator中打开并构建您的应用程序。使用命令行运行它,并用ldd来检查它,以确保从正确的位置的正确的库被加载,因为linuxdeployqt将在内部使用ldd来确定从哪里将库复制到bundle中。

QMake配置

重要: 默认情况下,linuxdeployqt部署$PATH指向的qmake指向Qt实例,所以确保它是正确的。在运行linuxdeployqt工具之前,验证qmake是否找到了正确的Qt实例:

qmake -v

QMake版本3.0
在 /tmp/.mount_QtCreator-5.7.0-x86_64/5.7/gcc_64/lib 中使用5.7.0的Qt版本

如果这并没有显示你想绑定的Qt实例的正确路径,那么调整你的$PATH来找到正确的qmake

或者,使用-qmake命令行选项将工具直接指向要使用的qmake可执行文件。

删除不必要的文件

在运行linuxdeployqt之前,删除不希望从构建目录分发的不需要的文件或许是明智的做法。这些可能会在构建过程中自动生成。你可以像这样删除它们:

find $HOME /build - * - * _ Qt_ * \(-name“moc_ *” - or - “* .o” - or - “qrc_ *” - or - name“Makefile *” - or - name “* .a“\)-exec rm {} \;

另外,你可以使用$DESTDIR

使用Linuxdeployqt与Travis CI

linuxdeployqt的常见用例是在make命令后面的Travis CI上使用它。以下示例说明如何在Travis CI中使用linuxdeployqt。创建一个类似于这个文件的.travis.yml文件(一定要定制它,例如,把’APPNAME改成你的应用程序的名字,因为它是在.desktop`文件的Name = ):

language: cpp
compiler: gcc
sudo: require
dist: trusty

before_install:
  - sudo add-apt-repository ppa:beineri/opt-qt592-trusty -y
  - sudo apt-get update -qq

install:
  - sudo apt-get -y install qt59base
  - source /opt/qt*/bin/qt*-env.sh

script:
  - qmake CONFIG+=release PREFIX=/usr
  - make -j$(nproc)
  - make INSTALL_ROOT=appdir -j$(nproc) install ; find appdir/
  - wget -c -q "https://github.com/probonopd/linuxdeployqt/releases/download/continuous/linuxdeployqt-continuous-x86_64.AppImage"
  - chmod a+x linuxdeployqt-continuous-x86_64.AppImage
  - unset QTDIR; unset QT_PLUGIN_PATH ; unset LD_LIBRARY_PATH
  - export VERSION=$(git rev-parse --short HEAD) # linuxdeployqt uses this for naming the file
  - ./linuxdeployqt-continuous-x86_64.AppImage appdir/usr/share/applications/*.desktop -bundle-non-qt-libs
  - ./linuxdeployqt-continuous-x86_64.AppImage appdir/usr/share/applications/*.desktop -appimage

after_success:
  - find ./appdir -executable -type f -exec ldd {} \; | grep " => /usr" | cut -d " " -f 2-3 | sort | uniq
  - # curl --upload-file ./APPNAME*.AppImage https://transfer.sh/APPNAME-git.$(git rev-parse --short HEAD)-x86_64.AppImage
  - wget -c https://github.com/probonopd/uploadtool/raw/master/upload.sh
  - bash upload.sh ./APPNAME*.AppImage*

branches:
  except:
    - # Do not build tags that we create when we upload to GitHub Releases
    - /^(?i:continuous)/

当你保存你的更改时,Travis CI会为你创建并上传一个AppImage。不过,可能一些微调仍然是必需的。

为了达到这个目的,如果你还没有这样做,你需要为你的版本库启用Travis CI

默认情况下,Qt Creator生成的qmake.pro文件不支持make install。在这种情况下,你会得到这样的错误:

make:Nothing to be done for `install'.
find: `appdir/': No such file or directory

如果qmake不允许make install或者无法安装桌面文件和图标,那么你需要改变.pro文件,类似于https://github.com/probonopd/FeedTheMonkey/blob/main/FeedTheMonkey.pro。

  - make INSTALL_ROOT=appdir install ; find appdir/

CMake 需要DESTDIR来代替:

  - cmake . -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr
  - make -j$(nproc)
  - make DESTDIR=appdir -j$(nproc) install ; find appdir/

autotools(“find…”将会花费大量的时间)也要DESTDIR,如果使用一个绝对的链接,我们可以用readlink链接它:

  - ./configure --prefix=/usr
  - make -j$(nproc)
  - make install DESTDIR=$(readlink -f appdir) ; find appdir/

注意,如果你遇到

qmake PREFIX=/usr CONFIG+=use_qt_paths

在这里,CONFIG + = use_qt_paths需要被删除,否则在使用beineri ppa的时候,它会在/opt/qt58的Qt安装路径下安装所有的东西。

不同之处在于你正在构建Qt库,应该将Qt库安装到Qt驻留在你的系统的同一个位置,从linuxdeployqt选择它。

在GitHub上发送合并请求

linuxdeployqt非常适合上游应用程序项目,它们可以快速地以二进制形式向Linux用户发布其软件,而且没有太多的开销。如果您希望看到特定的应用程序使用linuxdeployqt,那么发送合并请求可能是上游应用程序项目考虑的一个选项。对于合并请求,您可以使用以下模板文本,但一定要将其定制到相关项目中。

这个PR合并后,将在每个`git push`上的[Travis CI](https://travis-ci.org/)上编译这个应用程序,并上传一个[AppImage](http://appimage.org/)到你的GitHub发布页面。

提供[AppImage](http://appimage.org/)将具有以下优点:
- 作为AppImage打包的应用程序可以在许多发行版上运行(包括Ubuntu,Fedora,openSUSE,CentOS,basicOS,Linux Mint等)
- 一个应用程序=一个文件=用户可以非常简单的使用:只需下载一个AppImage文件,[使其可执行](http://discourse.appimage.org/t/how-to-make-an-appimage-executable/80) ,然后运行
- 不需要解包或安装
- 不需要root权限
- 没有系统库改变
- 开箱即用,无需安装运行时(run time)
- 可选择与桌面集成`appimaged`
- 可选择二进制增量更新,例如,用于连续构建(仅下载二进制比较)使用AppImageUpdate
- 可以选择GPG2 - 签署你的AppImages(在文件内)
- 在Live ISOs上工作
- 双启动多个发行版时可以使用相同的AppImages
- 可以展示在AppImage的[AppImageHub](https://appimage.github.io/apps)主目录中
- 可以使用“--appimage-extract”参数作为自解压压缩归档

[这里是一个概述](https://appimage.github.io/apps)已经分发上游提供的官方AppImages项目。

__PLEASE注意:__为了这个工作,你需要为你的仓库启用Travis CI(这里描述)(https://travis-ci.org/getting_started)__prior合并this__,如果你还没有这样做的话。此外,您需要在Travis CI中设置“GITHUB_TOKEN”才能正常工作;请参阅https://github.com/probonopd/uploadtool。
如果您希望在项目历史记录中只看到一个合并请求条目,请启用[此GitHub功能](https://help.github.com/articles/configuring-commit-squashing-for-pull-requests /)在您的回购。它允许您在合并时压缩(合并)提交。

如果您有任何问题,可以和AppImage开发人员在IRC:irc.freenode.net上的#AppImage频道与其交流。

使用linuxdeployqt的项目

这些项目已经在使用Travis CI和linuxdeployqt来提供AppImage的构建:

  • https://github.com/probonopd/ImageMagick
  • https://github.com/Subsurface-divelog/subsurface/
  • https://github.com/jimevins/glabels-qt
  • https://travis-ci.org/NeoTheFox/RepRaptor
  • https://github.com/electronpass/electronpass-desktop
  • https://github.com/lirios/browser
  • https://github.com/jeena/FeedTheMonkey
  • https://github.com/labsquare/fastQt/
  • https://github.com/sqlitebrowser/sqlitebrowser/
  • https://github.com/neuro-sys/tumblr-downloader-client
  • https://github.com/LongSoft/UEFITool
  • https://github.com/dannagle/PacketSender
  • https://github.com/nuttyartist/notes
  • https://github.com/leozide/leocad/
  • https://github.com/Blinkinlabs/PatternPaint
  • https://github.com/fathomssen/redtimer
  • https://github.com/coryo/amphetype2
  • https://github.com/chkmue/MyQtTravisTemplateProject
  • https://github.com/chkmue/qttravisCI_1
  • https://github.com/eteran/edb-debugger
  • https://github.com/crapp/labpowerqt/
  • https://github.com/probonopd/linuxdeployqt/显然;-)
  • https://github.com/xdgurl/xdgurl
  • https://github.com/QNapi/qnapi

该项目已经在定制的Jenkins工作流程中使用了linuxdeployqt:

  • https://github.com/appimage-packages/

这些项目已经在使用linuxdeployqt:

  • 用于Linux的Autodesk EAGLE http://www.autodesk.com/products/eagle/free-download
  • https://github.com/bjorn/tiled/
  • https://github.com/evpo/EncryptPad
  • https://github.com/grahamrow/Muview2
  • https://github.com/freemountain/quark/
  • https://github.com/Mr0815/geraetepruefung/

GitLab上的这个项目使用linuxdeployqt:

  • https://gitlab.com/rpdev/opentodolist

这些可以使用linuxdeployqt成功捆绑:

  • https://github.com/probonopd/tiled/blob/patch-1/.travis.yml
  • https://gitlab.com/rpdev/opentodolist/issues/96

贡献

一个非常好的贡献方式就是是将合并请求发送到您希望使用linuxdeployqt的应用程序项目,如上所述。也欢迎您为linuxdeployqt开发本身作出贡献。请在forum或使用GitHub问题和Pull Requests进行讨论。

联系

开发者在irc.freenode.net的#AppImage频道


改进文档质量