用 linuxdeployqt 把 Qt 应用部署到 Linux

原文:How to Deploy Your Qt Cross-Platform Applications to Linux Operating System With linuxdeployqt

演示环境

操作系统:

OS

Qt代码:

code

准备工作

Release模式Build源代码:

build the code

试着运行编译好的Qt代码:

run the code

找到Release Build的文件夹位置:
Qt Creator

build directory outside

build directory inside

用linuxdeployqt在Linux上部署应用

Step 1 . Set up the deployment directory

Image for post

Step 2. Go to linuxdeployqt github

probonopd/linuxdeployqt

Step 3. Download the latest release of linuxdeployqt from github

The first option to download the release,
The second option to download the release:
Download the .AppImage

Step 4. Grant execution rights to the downloaded file

Image for post

Image for post

Step 5. Execute the file through terminal shell command

Executing the .AppImage file provides you with hints about how to use it

georgeca@georgeca-VirtualBox:~/Downloads$ ./linuxdeployqt-5-x86_64.AppImage 
linuxdeployqt 4 (commit 8b3ded6), build 571 built on 2018-10-07 20:58:12 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.
   -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.

Step 6. Save the image file which will serve as the application’s icon

Step 7. Write the .desktop text file and save it in the deployment directory, alongside the executable

用 linuxdeployqt 把 Qt 应用部署到 Linux

Here are the specifications for writing .desktop files: specifications.freedesktop.org/des...

用 linuxdeployqt 把 Qt 应用部署到 Linux

This is an example of a .desktop file

[Desktop Entry]
Type=Application
Name=WaterMonitoringSystem
Comment=This is an application that measures levels in the tank and shows warning signals as traffic lights
Exec=WaterLevelMonitoringSystem
Icon=penguin

Step 8. Run the linuxdeployqt with the path to the executable and the other relevant arguments

Potential error: missing qmake in $PATH variable

georgeca@georgeca-VirtualBox:~/Qt-Tutorials/Deployment/deploy-with-linuxdeployqt$ cd ~
georgeca@georgeca-VirtualBox:~$ cd Downloads/
georgeca@georgeca-VirtualBox:~/Downloads$ ls -lh
total 360M
-rw-rw-r-- 1 georgeca georgeca 1,2K sep 10 15:44 0001-georges-led-pin9_23.patch
-rw-rw-r-- 1 georgeca georgeca 241M sep  8 09:24 eclipse-cpp-2020-06-R-linux-gtk-x86_64.tar.gz
-rw-rw-r-- 1 georgeca georgeca 105M sep  8 09:38 gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf.tar.xz
-rwxrwxr-x 1 georgeca georgeca  14M nov 17 12:07 linuxdeployqt-5-x86_64.AppImage
georgeca@georgeca-VirtualBox:~/Downloads$ ./linuxdeployqt-5-x86_64.AppImage ~/Qt-Tutorials/Deployment/deploy-with-linuxdeployqt/WaterLevelMonitoringSystem
linuxdeployqt 4 (commit 8b3ded6), build 571 built on 2018-10-07 20:58:12 UTC
Not using FHS-like mode
app-binary: "/home/georgeca/Qt-Tutorials/Deployment/deploy-with-linuxdeployqt/WaterLevelMonitoringSystem"
appDirPath: "/home/georgeca/Qt-Tutorials/Deployment/deploy-with-linuxdeployqt"
relativeBinPath: "WaterLevelMonitoringSystem"
ERROR: qmake not found on the $PATH

Solution: Add qmake path to the environment $PATH variable

用 linuxdeployqt 把 Qt 应用部署到 Linux

Delete the files already generated

用 linuxdeployqt 把 Qt 应用部署到 Linux

用 linuxdeployqt 把 Qt 应用部署到 Linux

Run the terminal command to add its path to the $PATH environment variable

Get the directory path towards the ‘bin’ directory:

georgeca@georgeca-VirtualBox:~/Qt/5.14.2/gcc_64$ cd bin/
georgeca@georgeca-VirtualBox:~/Qt/5.14.2/gcc_64/bin$ pwd
/home/georgeca/Qt/5.14.2/gcc_64/bin

Add to the $PATH variable

georgeca@georgeca-VirtualBox:~/Qt/5.14.2/gcc_64/bin$ export PATH=/home/georgeca/Qt/5.14.2/gcc_64/bin/:$PATH

After adding the qmake path, the environment variable $PATH is going to look like this:

用 linuxdeployqt 把 Qt 应用部署到 Linux

Finally:

OPTION 1: Run linuxdeployqt to deploy the necessary Qt libraries inside the deployment directory

用 linuxdeployqt 把 Qt 应用部署到 Linux

The outcome is:

![Image for post](https://miro.medium.com/max/60/1*ge8wKSq2m7yz_toHS-Z-0w.png?q=20)

![Image for post](https://miro.medium.com/max/1973/1*ge8wKSq2m7yz_toHS-Z-0w.png)

The directories in the deployment contain all the necessary Qt libraries to run the application:

georgeca@georgeca-VirtualBox:~/Qt-Tutorials/Deployment/deploy-with-linuxdeployqt$ tree -L 3 .
.
├── AppRun -> WaterLevelMonitoringSystem
├── lib
│   ├── libicudata.so.56
│   ├── libicui18n.so.56
│   ├── libicuuc.so.56
│   ├── libQt5Core.so.5
│   ├── libQt5DBus.so.5
│   ├── libQt5Gui.so.5
│   ├── libQt5Network.so.5
│   ├── libQt5QmlModels.so.5
│   ├── libQt5Qml.so.5
│   ├── libQt5Quick.so.5
│   ├── libQt5VirtualKeyboard.so.5
│   ├── libQt5Widgets.so.5
│   └── libQt5XcbQpa.so.5
├── plugins
│   ├── imageformats
│   │   ├── libqgif.so
│   │   ├── libqicns.so
│   │   ├── libqico.so
│   │   ├── libqjpeg.so
│   │   ├── libqtga.so
│   │   ├── libqtiff.so
│   │   ├── libqwbmp.so
│   │   └── libqwebp.so
│   ├── platforminputcontexts
│   │   ├── libcomposeplatforminputcontextplugin.so
│   │   ├── libibusplatforminputcontextplugin.so
│   │   └── libqtvirtualkeyboardplugin.so
│   ├── platforms
│   │   └── libqxcb.so
│   └── xcbglintegrations
│       ├── libqxcb-egl-integration.so
│       └── libqxcb-glx-integration.so
├── qt.conf
├── translations
│   ├── qt_ar.qm
│   ├── qt_bg.qm
│   ├── qt_ca.qm
│   ├── qt_cs.qm
│   ├── qt_da.qm
│   ├── qt_de.qm
│   ├── qt_en.qm
│   ├── qt_es.qm
│   ├── qt_fi.qm
│   ├── qt_fr.qm
│   ├── qt_gd.qm
│   ├── qt_he.qm
│   ├── qt_hu.qm
│   ├── qt_it.qm
│   ├── qt_ja.qm
│   ├── qt_ko.qm
│   ├── qt_lv.qm
│   ├── qt_pl.qm
│   ├── qt_ru.qm
│   ├── qt_sk.qm
│   ├── qt_uk.qm
│   └── qt_zh_TW.qm
├── WaterLevelMonitoringSystem
└── WaterLevelMonitoringSystem.desktop.desktop

7 directories, 53 files

OPTION 2: Create a single .AppImage executable file to deploy the Qt Application on Linux

用 linuxdeployqt 把 Qt 应用部署到 Linux

georgeca@georgeca-VirtualBox:~/Downloads$ ./linuxdeployqt-5-x86_64.AppImage ~/Qt-Tutorials/Deployment/deploy-with-linuxdeployqt/WaterLevelMonitoringSystem -appimage
linuxdeployqt 4 (commit 8b3ded6), build 571 built on 2018-10-07 20:58:12 UTC
Not using FHS-like mode
app-binary: "/home/georgeca/Qt-Tutorials/Deployment/deploy-with-linuxdeployqt/WaterLevelMonitoringSystem"
appDirPath: "/home/georgeca/Qt-Tutorials/Deployment/deploy-with-linuxdeployqt"
relativeBinPath: "WaterLevelMonitoringSystem"
WARNING: "/home/georgeca/Qt-Tutorials/Deployment/deploy-with-linuxdeployqt/qt.conf" already exists, will not overwrite.
appimagetool, continuous build (commit d185526), build 1855 built on 2018-10-07 20:18:45 UTC
Desktop file: /home/georgeca/Qt-Tutorials/Deployment/deploy-with-linuxdeployqt/WaterLevelMonitoringSystem.desktop.desktop
Name: WaterLevelMonitoringSystem
Icon: penguin
Exec: WaterLevelMonitoringSystem
Comment: This is an application that measures levels in the tank and shows warning signals as traffic lights
Type: Application
Categories entry not found in desktop file
Categories: (null)
/home/georgeca/Qt-Tutorials/Deployment/deploy-with-linuxdeployqt/plugins/xcbglintegrations/libqxcb-glx-integration.so used for determining architecture x86_64
/home/georgeca/Qt-Tutorials/Deployment/deploy-with-linuxdeployqt/plugins/xcbglintegrations/libqxcb-egl-integration.so used for determining architecture x86_64
/home/georgeca/Qt-Tutorials/Deployment/deploy-with-linuxdeployqt/plugins/imageformats/libqgif.so used for determining architecture x86_64
/home/georgeca/Qt-Tutorials/Deployment/deploy-with-linuxdeployqt/plugins/imageformats/libqtiff.so used for determining architecture x86_64
/home/georgeca/Qt-Tutorials/Deployment/deploy-with-linuxdeployqt/plugins/imageformats/libqico.so used for determining architecture x86_64
/home/georgeca/Qt-Tutorials/Deployment/deploy-with-linuxdeployqt/plugins/imageformats/libqjpeg.so used for determining architecture x86_64
/home/georgeca/Qt-Tutorials/Deployment/deploy-with-linuxdeployqt/plugins/imageformats/libqwbmp.so used for determining architecture x86_64
/home/georgeca/Qt-Tutorials/Deployment/deploy-with-linuxdeployqt/plugins/imageformats/libqwebp.so used for determining architecture x86_64
/home/georgeca/Qt-Tutorials/Deployment/deploy-with-linuxdeployqt/plugins/imageformats/libqicns.so used for determining architecture x86_64
/home/georgeca/Qt-Tutorials/Deployment/deploy-with-linuxdeployqt/plugins/imageformats/libqtga.so used for determining architecture x86_64
/home/georgeca/Qt-Tutorials/Deployment/deploy-with-linuxdeployqt/plugins/bearer/libqconnmanbearer.so used for determining architecture x86_64
/home/georgeca/Qt-Tutorials/Deployment/deploy-with-linuxdeployqt/plugins/bearer/libqnmbearer.so used for determining architecture x86_64
/home/georgeca/Qt-Tutorials/Deployment/deploy-with-linuxdeployqt/plugins/bearer/libqgenericbearer.so used for determining architecture x86_64
/home/georgeca/Qt-Tutorials/Deployment/deploy-with-linuxdeployqt/plugins/platforminputcontexts/libqtvirtualkeyboardplugin.so used for determining architecture x86_64
/home/georgeca/Qt-Tutorials/Deployment/deploy-with-linuxdeployqt/plugins/platforminputcontexts/libibusplatforminputcontextplugin.so used for determining architecture x86_64
/home/georgeca/Qt-Tutorials/Deployment/deploy-with-linuxdeployqt/plugins/platforminputcontexts/libcomposeplatforminputcontextplugin.so used for determining architecture x86_64
/home/georgeca/Qt-Tutorials/Deployment/deploy-with-linuxdeployqt/plugins/platforms/libqxcb.so used for determining architecture x86_64
/home/georgeca/Qt-Tutorials/Deployment/deploy-with-linuxdeployqt/lib/libXdmcp.so.6 used for determining architecture x86_64
/home/georgeca/Qt-Tutorials/Deployment/deploy-with-linuxdeployqt/lib/libk5crypto.so.3 used for determining architecture x86_64
/home/georgeca/Qt-Tutorials/Deployment/deploy-with-linuxdeployqt/lib/libQt5Network.so.5 used for determining architecture x86_64
/home/georgeca/Qt-Tutorials/Deployment/deploy-with-linuxdeployqt/lib/libxcb-glx.so.0 used for determining architecture x86_64
/home/georgeca/Qt-Tutorials/Deployment/deploy-with-linuxdeployqt/lib/libgssapi_krb5.so.2 used for determining architecture x86_64
/home/georgeca/Qt-Tutorials/Deployment/deploy-with-linuxdeployqt/lib/libQt5XcbQpa.so.5 used for determining architecture x86_64
/home/georgeca/Qt-Tutorials/Deployment/deploy-with-linuxdeployqt/lib/libGLdispatch.so.0 used for determining architecture x86_64
/home/georgeca/Qt-Tutorials/Deployment/deploy-with-linuxdeployqt/lib/libkrb5support.so.0 used for determining architecture x86_64
/home/georgeca/Qt-Tutorials/Deployment/deploy-with-linuxdeployqt/lib/libQt5DBus.so.5 used for determining architecture x86_64
/home/georgeca/Qt-Tutorials/Deployment/deploy-with-linuxdeployqt/lib/libxkbcommon.so.0 used for determining architecture x86_64
/home/georgeca/Qt-Tutorials/Deployment/deploy-with-linuxdeployqt/lib/libXau.so.6 used for determining architecture x86_64
/home/georgeca/Qt-Tutorials/Deployment/deploy-with-linuxdeployqt/lib/libQt5Widgets.so.5 used for determining architecture x86_64
/home/georgeca/Qt-Tutorials/Deployment/deploy-with-linuxdeployqt/lib/libpng16.so.16 used for determining architecture x86_64
/home/georgeca/Qt-Tutorials/Deployment/deploy-with-linuxdeployqt/lib/libkrb5.so.3 used for determining architecture x86_64
/home/georgeca/Qt-Tutorials/Deployment/deploy-with-linuxdeployqt/lib/libgcrypt.so.20 used for determining architecture x86_64
/home/georgeca/Qt-Tutorials/Deployment/deploy-with-linuxdeployqt/lib/libXext.so.6 used for determining architecture x86_64
/home/georgeca/Qt-Tutorials/Deployment/deploy-with-linuxdeployqt/lib/libsystemd.so.0 used for determining architecture x86_64
/home/georgeca/Qt-Tutorials/Deployment/deploy-with-linuxdeployqt/lib/libgthread-2.0.so.0 used for determining architecture x86_64
/home/georgeca/Qt-Tutorials/Deployment/deploy-with-linuxdeployqt/lib/libxkbcommon-x11.so.0 used for determining architecture x86_64
/home/georgeca/Qt-Tutorials/Deployment/deploy-with-linuxdeployqt/lib/libbsd.so.0 used for determining architecture x86_64
/home/georgeca/Qt-Tutorials/Deployment/deploy-with-linuxdeployqt/lib/libQt5QmlModels.so.5 used for determining architecture x86_64
/home/georgeca/Qt-Tutorials/Deployment/deploy-with-linuxdeployqt/lib/libQt5Qml.so.5 used for determining architecture x86_64
/home/georgeca/Qt-Tutorials/Deployment/deploy-with-linuxdeployqt/lib/libicudata.so.56 used for determining architecture x86_64
/home/georgeca/Qt-Tutorials/Deployment/deploy-with-linuxdeployqt/lib/libxcb-xfixes.so.0 used for determining architecture x86_64
/home/georgeca/Qt-Tutorials/Deployment/deploy-with-linuxdeployqt/lib/libxcb-xkb.so.1 used for determining architecture x86_64
/home/georgeca/Qt-Tutorials/Deployment/deploy-with-linuxdeployqt/lib/libQt5Quick.so.5 used for determining architecture x86_64
/home/georgeca/Qt-Tutorials/Deployment/deploy-with-linuxdeployqt/lib/libdbus-1.so.3 used for determining architecture x86_64
/home/georgeca/Qt-Tutorials/Deployment/deploy-with-linuxdeployqt/lib/libQt5VirtualKeyboard.so.5 used for determining architecture x86_64
/home/georgeca/Qt-Tutorials/Deployment/deploy-with-linuxdeployqt/lib/libicuuc.so.56 used for determining architecture x86_64
/home/georgeca/Qt-Tutorials/Deployment/deploy-with-linuxdeployqt/lib/libQt5Gui.so.5 used for determining architecture x86_64
/home/georgeca/Qt-Tutorials/Deployment/deploy-with-linuxdeployqt/lib/liblzma.so.5 used for determining architecture x86_64
/home/georgeca/Qt-Tutorials/Deployment/deploy-with-linuxdeployqt/lib/libicui18n.so.56 used for determining architecture x86_64
/home/georgeca/Qt-Tutorials/Deployment/deploy-with-linuxdeployqt/lib/libQt5Core.so.5 used for determining architecture x86_64
/home/georgeca/Qt-Tutorials/Deployment/deploy-with-linuxdeployqt/lib/liblz4.so.1 used for determining architecture x86_64
/home/georgeca/Qt-Tutorials/Deployment/deploy-with-linuxdeployqt/lib/libGLX.so.0 used for determining architecture x86_64
/home/georgeca/Qt-Tutorials/Deployment/deploy-with-linuxdeployqt/lib/libX11-xcb.so.1 used for determining architecture x86_64
/home/georgeca/Qt-Tutorials/Deployment/deploy-with-linuxdeployqt/lib/libpcre.so.3 used for determining architecture x86_64
/home/georgeca/Qt-Tutorials/Deployment/deploy-with-linuxdeployqt/WaterLevelMonitoringSystem used for determining architecture x86_64
Using architecture x86_64
App name for filename: WaterLevelMonitoringSystem
/home/georgeca/Qt-Tutorials/Deployment/deploy-with-linuxdeployqt should be packaged as WaterLevelMonitoringSystem-x86_64.AppImage
Deleting pre-existing .DirIcon
Creating .DirIcon symlink based on information from desktop file
Generating squashfs...
Size of the embedded runtime: 187784 bytes
mksquashfs commandline: /tmp/.mount_linuxdBLwf77/usr/bin/../lib/appimagekit/mksquashfs /home/georgeca/Qt-Tutorials/Deployment/deploy-with-linuxdeployqt WaterLevelMonitoringSystem-x86_64.AppImage -offset 187784 -comp gzip -root-owned -noappend -mkfs-fixed-time 0 
Parallel mksquashfs: Using 2 processors
Creating 4.0 filesystem on WaterLevelMonitoringSystem-x86_64.AppImage, block size 131072.
[===========================================================================================================================================================================================-] 730/730 100%

Exportable Squashfs 4.0 filesystem, gzip compressed, data block size 131072
    compressed data, compressed metadata, compressed fragments, compressed xattrs
    duplicates are removed
Filesystem size 32075.81 Kbytes (31.32 Mbytes)
    37.54% of uncompressed filesystem size (85453.68 Kbytes)
Inode table size 3593 bytes (3.51 Kbytes)
    49.61% of uncompressed inode table size (7243 bytes)
Directory table size 1441 bytes (1.41 Kbytes)
    44.16% of uncompressed directory table size (3263 bytes)
Number of duplicate files found 8
Number of inodes 141
Number of files 105
Number of fragments 16
Number of symbolic links  2
Number of device nodes 0
Number of fifo nodes 0
Number of socket nodes 0
Number of directories 34
Number of ids (unique uids + gids) 1
Number of uids 1
    root (0)
Number of gids 1
    root (0)
Embedding ELF...
Marking the AppImage as executable...
Embedding MD5 digest
Success

Please consider submitting your AppImage to AppImageHub, the crowd-sourced
central directory of available AppImages, by opening a pull request
at https://github.com/AppImage/appimage.github.io

Outcome: .AppImage generated alongside linuxdeployqt file

用 linuxdeployqt 把 Qt 应用部署到 Linux

Upon double clicking the .AppImage file, one can run the file.

用 linuxdeployqt 把 Qt 应用部署到 Linux

本作品采用《CC 协议》,转载必须注明作者和本文链接
讨论数量: 0
(= ̄ω ̄=)··· 暂无内容!

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!