linuxdeployqt ツールを使用して Qt プロジェクトを Linux にデプロイする

linuxdeployqt ツールを使用して Qt プロジェクトを Linux にデプロイする

linuxdeployqt の依存関係

linuxdeployqt ツールの紹介

https://github.com/probonopd/linuxdeployqt

linuxdeployqt は、Linux プラットフォーム上で Qt アプリケーションをパッケージ化するためのツールです。その主な機能は、Qt アプリケーションの依存関係を自動的に処理し、独立した移植可能なアプリケーション パッケージを生成することです。Qt ライブラリ、プラグイン、およびアプリケーションが依存するその他のランタイム依存関係をパッケージ化し、アプリケーションに起動スクリプトやその他の必要なファイルを生成します。

linuxdeployqt を使用すると、Qt アプリケーションを、アプリケーションに必要なすべてのファイルと依存関係が含まれる単一のディレクトリにパッケージ化できます。これにより、すべての依存関係がアプリケーション パッケージにバンドルされるため、Qt ランタイムをインストールしなくてもアプリケーションを実行できます。さらに、linuxdeployqt は、一般的な Linux アプリケーションのパッケージ化および配布形式である AppImage 形式でアプリケーション パッケージを生成できます。

linuxdeployqt は、ターミナルで他のコマンドを実行するのと同じように使用できるコマンド ライン ツールです。パッケージ化する Qt アプリケーションのパスを指定すると、linuxdeployqt がアプリケーションの依存関係を自動的に分析し、パッケージ化されたアプリケーション パッケージを生成します。

要約すると、linuxdeployqt は、Qt アプリケーションを独立した移植可能なアプリケーション パッケージにパッケージ化して、Linux プラットフォーム上での配布と実行を容易にする便利なツールです。

linuxdeployqtのインストール

# 安装 curl 工具
apt-get install curl -y

# 从 github 中下载 linuxdeployqt 程序
sudo curl -L -o /usr/local/bin/linuxdeployqt https://github.com/probonopd/linuxdeployqt/releases/download/continuous/linuxdeployqt-continuous-x86_64.AppImage

# 给 linuxdeployqt 程序添加可执行权限
sudo chmod a+x linuxdeployqt-continuous-x86_64.AppImage

「chmod a+x」はファイルやディレクトリのパーミッションを変更するコマンドです。コマンドの説明は次のとおりです。

  • 「chmod」とは「change mode」の略で、ファイルやディレクトリのアクセスモード(パーミッション)を変更するために使用されます。
  • 「a」は「all」を表し、すべてのユーザーの権限を指します。
  • 「+」は権限を追加することを意味します。
  • 「x」は「execute」、つまり実行許可を意味します。
    したがって、「chmod a+x」コマンドは、すべてのユーザーにファイルまたはディレクトリへの実行権限を追加することを意味します。実行権限により、ユーザーはファイルを実行したり (実行可能ファイルの場合)、ディレクトリに入ることができます (ディレクトリの場合)。

linuxdeployqtの使用

詳細な使用方法については、次のコマンドラインを実行できます。

linuxdeployqt -h

出力内容は以下のとおりです。

linuxdeployqt  (commit 8428c59), build 47 built on 2023-04-23 17:29:33 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
   -qtlibinfix=<infix>      : Adapt the .so search if your Qt distribution has infix.
   -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.

上記の出力情報を見ると、Windows システムで Qt Windeployqt.exe ツールを使用するのと似ていることがわかります。

環境変数を構成する
  1. 端末を開き、管理者としてログインします。

  2. ファイルを編集します/etc/profile:

sudo nano /etc/profile

グラフィカル インターフェイスを備えたシステムを使用している場合は、sudo gedit /etc/profileコマンドを使用してファイルを編集できます。

  1. ファイルの末尾に以下を追加します。
export PATH=/opt/Qt/5.15.2/gcc_64/bin:$PATH
export LIB_PATH=/opt/Qt/5.15.2/gcc_64/lib:$LIB_PATH
export PLUGIN_PATH=/opt/Qt/5.15.2/gcc_64/plugins:$PLUGIN_PATH
export QML2_PATH=/opt/Qt/5.15.2/gcc_64/qml:$QML2_PATH
  1. を押してCtrl + Oファイルを保存し、Ctrl + Xエディタを閉じます。

  2. 変更を有効にするには、ターミナルを再起動するか、ログアウトしてから再度ログインします。または、コマンドを使用して、現在のシェルで変更をすぐに有効にすることもできますsource /etc/profile

この構成はすべてのユーザーに適用されるため、環境変数を変更する前に、その影響を理解し、他のユーザーの環境を中断しないようにしてください。特定のユーザーに対してのみ環境変数を設定したい場合は、そのユーザーの~/.bashrcファイルを編集し~/.profile、それに環境変数を追加できます。

通常の (非 QML) プログラムの場合

次のコマンドを実行して、関連する依存関係をアプリケーション ディレクトリに自動的にパッケージ化します。

linuxdeployqt <应用程序> -appimage 
QML プログラムの場合

linuxdeployqtプロジェクトのソース コード ディレクトリ (システム Qt ディレクトリではない) を指定し、ソース コード ディレクトリ内のファイルをスキャンして*.qml依存関係情報を取得する必要があります。これにより、QML 関連の依存関係が自動的にコピーされます。

linuxdeployqt <应用程序> -appimage -qmldir <指向项目源代码路径> 

これらのコマンドは、Qt アプリケーションをパッケージ化して Linux プラットフォームにデプロイするのに役立ちます。

パッケージ化されたプログラムは以下のとおりです。
linuxdeployqt ツールを使用して Qt プロジェクトを Linux にデプロイする

このディレクトリをデプロイする必要があるシステムにコピーして実行するだけです。

おすすめ

転載: blog.csdn.net/cheungxiongwei/article/details/131737576