序文
Linux環境では、Qtプログラムを開発した後、インストールパッケージや実行ファイルにして配布する必要があります。ここでは、linuxdeployqt を使用して Qt プログラムを.AppImage
アプリケーションとしてパッケージ化する方法を紹介します (Windows のグリーン インストール不要ソフトウェアと同様)
環境構成
Qt 環境変数を構成する
このステップでは、linuxdeployqt
ツールが Qt 環境を認識できるようにします。bashrc
ファイルを編集する
vim ~/.bashrc
最後の行の後に独自の Qt 環境を追加します
#QT ENV
export QTDIR=/home/leo/Qt/5.15.2/gcc_64
export PATH=$QTDIR/bin:$PATH
export LD_LIBRARY_PATH=$QTDIR/lib:$LD_LIBRARY_PATH
export QT_PLUGIN_PATH=$QTDIR/plugins:$QT_PLUGIN_PATH
export QML2_PATH=$QTDIR/qml:$QML2_PATH
すぐに効果的
source ~/.bashrc
確認する
qmake -v
linuxdeployqt を構成する
linuxdeployqtに移動して、リリースされたリリースをダウンロードしますlinuxdeployqt-continuous-x86_64.AppImage
次に、実行権限を付与し、使いやすいように名前を変更し、/usr/local/bin
どこでも簡単に使用できるようにパスに配置します。
chmod 777 linuxdeployqt-continuous-x86_64.AppImage
mv linuxdeployqt-continuous-x86_64.AppImage linuxdeployqt
sudo mv linuxdeployqt /usr/local/bin
テストを受けてください
linuxdelpoyqt --version
AppImageKitを構成する
AppImageKitに移動してダウンロードしますappimagetool-x86_64.AppImage
同様に、実行権限を追加します。
chmod 777 appimagetool-x86_64.AppImage
インストールパッチルフ
apt で patchelf を直接インストールするだけです
sudo apt install patchelf
パック
アプリケーションを出力ディレクトリにコピーし、コマンドを実行します (ここでは、QClipboard 実行可能プログラムを例にします)。
leo@leo-VirtualBox:~/Desktop/output$ linuxdeployqt QClipboard -appimage
linuxdeployqt (commit 6fcaf74), build 55 built on 2023-09-23 13:33:41 UTC
Not using FHS-like mode
app-binary: "/home/leo/Desktop/output/QClipboard"
appDirPath: "/home/leo/Desktop/output"
relativeBinPath: "QClipboard"
ERROR: Desktop file missing, creating a default one (you will probably want to edit it)
ERROR: Icon file missing, creating a default one (you will probably want to edit it)
qmakePath 3= ""
appimagetool, continuous build (commit 8bbf694), build <local dev build> built on 2020-12-31 11:48:33 UTC
fatal: 不是 git 仓库(或者任何父目录):.git
Failed to run 'git rev-parse --short HEAD: Child process exited with code 128 (code 128)
Desktop file: /home/leo/Desktop/output/default.desktop
Categories entry not found in desktop file
.desktop file is missing a Categories= key
すると、出力ディレクトリにいくつかのファイルが生成されていることがわかります。
lrwxrwxrwx 1 leo leo 10 11月 3 21:31 AppRun -> QClipboard
-rw-rw-r-- 1 leo leo 123 11月 3 21:31 default.desktop
-rw-rw-r-- 1 leo leo 0 11月 3 21:31 default.png
drwxrwxr-x 6 leo leo 4096 11月 3 21:31 doc
drwxrwxr-x 2 leo leo 4096 11月 3 21:32 lib
drwxrwxr-x 7 leo leo 4096 11月 3 21:32 plugins
-rwxrwxr-x 1 leo leo 157512 11月 3 21:30 QClipboard
-rw-rw-r-- 1 leo leo 145 11月 3 21:32 qt.conf
drwxrwxr-x 2 leo leo 4096 11月 3 21:32 translations
デスクトップファイルを変更する
デフォルトで生成されたデスクトップファイルを変更する必要があります
leo@leo-VirtualBox :~/Desktop/output$ cat default. desktop
[Desktop Entry]
Type=Application
Name=Application
Exec=AppRun %F
Icon=default
Comment=Edit this default file
Terminal=true
デスクトップ ファイルの仕様を表示して変更できます。
ここでは、default.desktop ファイルの名前が QClipboard.desktop ファイルに変更され、次の内容に変更されます。
[Desktop Entry]
Categories=System; Office;
Type=Application
Keywords=clip; clipboard;
Name=QClipboard
Exec=AppRun %F
Icon=logo
Comment=A cross-platform clipboard tool that allows selecting items from clipboard history to paste.
Terminal=true
次に、冗長なフォルダーを削除すると、最終的な効果は次のようになります。
appimage アプリケーションを生成する
appimagetool を使用して appimage アプリケーションを生成します。
実行./appimagetool-x 86_64. AppImage output/
後に続くのはoutput
出力ディレクトリです。
注: ダウンロードしたアプリケーションはパスにappimagetool-x 86_64. AppImage
配置されていないため、直接実行することはできません。/usr/local/bin
leo@leo-VirtualBox :~/Downloads$ ./appimagetool-x 86_64. AppImage ~/Desktop/output/
appimagetool, continuous build (commit 8 bbf 694), build <local dev build> built on 2020-12-31 11:48:33 UTC
/home/leo/Desktop/output/QClipboard. desktop: hint: value "System; Office;" for key "Categories" in group "Desktop Entry" contains more than one main category; application might appear more than once in the application menu
Using architecture x 86_64
/home/leo/Desktop/output should be packaged as QClipboard-x 86_64. AppImage
WARNING: AppStream upstream metadata is missing, please consider creating it
in usr/share/metainfo/QClipboard. appdata. xml
Please see https://www.freedesktop.org/software/appstream/docs/chap-Quickstart.html#sect-Quickstart-DesktopApps
for more information or use the generator at http://output.jsbin.com/qoqukof.
Generating squashfs...
Parallel mksquashfs: Using 6 processors
Creating 4.0 filesystem on QClipboard-x 86_64. AppImage, block size 131072.
[========================================================================/] 530/530 100%
Exportable Squashfs 4.0 filesystem, gzip compressed, data block size 131072
compressed data, compressed metadata, compressed fragments,
compressed xattrs, compressed ids
duplicates are removed
Filesystem size 25011.83 Kbytes (24.43 Mbytes)
39.56% of uncompressed filesystem size (63223.96 Kbytes)
Inode table size 2316 bytes (2.26 Kbytes)
55.20% of uncompressed inode table size (4196 bytes)
Directory table size 861 bytes (0.84 Kbytes)
52.25% of uncompressed directory table size (1648 bytes)
Number of duplicate files found 0
Number of inodes 69
Number of files 59
Number of fragments 12
Number of symbolic links 2
Number of device nodes 0
Number of fifo nodes 0
Number of socket nodes 0
Number of directories 8
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 MD 5 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
次に、同じレベルのパスの下にappimagetool-x 86_64. AppImage
生成されたQClipboard-x 86_64. AppImage
パッケージを確認できます。
テストの実行
QClipboard アプリケーションが正常に実行されました
他の人に配布する場合は、実行するための実行権限を追加する必要があることに注意してください。
要約する
上記は、Linux システムで Qt プログラムを AppImage プログラムにパッケージ化するプロセス全体です。
同時に、クロスプラットフォームのクリップボード ツールにスターを付けることも歓迎します: https://github.com/L-Super/QClipboard
https://blog.csdn.net/zyhse/article/details/106381937
https://www.cnblogs.com/linuxAndMcu/p/11016322.html
UnityLaunchersAndDesktopFiles - コミュニティ ヘルプ Wiki (ubuntu.com)