Deploy Qt projects on Linux using the linuxdeployqt tool

Deploy Qt projects on Linux using the linuxdeployqt tool

linuxdeployqt dependencies

linuxdeployqt tool introduction

https://github.com/probonopd/linuxdeployqt

linuxdeployqt is a tool for packaging Qt applications on the Linux platform. Its main function is to automatically handle the dependencies of Qt applications and generate an independent, portable application package. It packages the Qt libraries, plug-ins, and other runtime dependencies that the application depends on, and generates startup scripts and other necessary files for the application.

Using linuxdeployqt, you can package your Qt application into a single directory that contains all the files and dependencies required by the application. This allows applications to be run without installing the Qt runtime since all dependencies are bundled in the application package. In addition, linuxdeployqt can generate application packages in AppImage format, a popular Linux application packaging and distribution format.

linuxdeployqt is a command line tool that can be used similar to running other commands in the terminal. You can specify the path of the Qt application to be packaged, and then linuxdeployqt will automatically analyze the application's dependencies and generate a packaged application package.

In summary, linuxdeployqt is a convenient tool for packaging Qt applications into independent, portable application packages, making them easier to distribute and run on the Linux platform.

linuxdeployqt installation

# 安装 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" is a command used to change permissions on a file or directory. Here's an explanation of the command:

  • "chmod" is the abbreviation of "change mode", which is used to change the access mode (permissions) of a file or directory.
  • "a" stands for "all" and refers to permissions for all users.
  • "+" means adding permissions.
  • "x" means "execute", which means execution permission.
    So, the "chmod a+x" command means to add execute permissions to a file or directory to all users. Execute permission allows the user to execute the file (for an executable file) or enter the directory (for a directory).

linuxdeployqt use

For detailed usage, you can execute the following command line

linuxdeployqt -h

The output content is as follows:

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.

Looking at the above output information, you can find that it is similar to using the Qt windeployqt.exe tool in Windows systems.

Configure environment variables
  1. Open a terminal and log in as administrator.

  2. Edit /etc/profilefile:

sudo nano /etc/profile

If you are using a system with a graphical interface, you can use sudo gedit /etc/profilecommands to edit files.

  1. Add the following at the end of the file:
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. Press Ctrl + Oto save the file and then to Ctrl + Xclose the editor.

  2. Restart the terminal or log out and back in for the changes to take effect, or they can take effect immediately in the current shell, using the command source /etc/profile.

Note that this configuration will apply to all users, so before changing environment variables, make sure you understand the impact and ensure you do not disrupt other users' environments. If you only want to set environment variables for a specific user, you can edit that user's ~/.bashrcfile or ~/.profilefiles and add the environment variables to it.

For regular (non-QML) programs

Execute the following command to automatically package relevant dependencies into the application directory:

linuxdeployqt <应用程序> -appimage 
For QML programs

You need to specify the project source code directory (not the system Qt directory) and linuxdeployqtscan the files in the source code directory *.qmlto obtain dependency information. This will automatically copy QML-related dependencies.

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

These commands will help you package and deploy Qt applications on the Linux platform.

The packaged program is as shown below:
Deploy Qt projects on Linux using the linuxdeployqt tool

Just copy this directory to the system that needs to be deployed and run it.

Guess you like

Origin blog.csdn.net/cheungxiongwei/article/details/131737576