Solve the problem of using linuxdeployqt to package Qt programs in Ubuntu

Solve the problem of using linuxdeployqt to package Qt programs in Ubuntu

I wrote some Qt interface programs, but found it difficult to port them to other computers that do not have the Qt environment installed. After checking the information, I learned that there is a windowsdeployqt program on windows and a linuxdeployqt on linux that can help us package quickly.

1. Configure the Qt environment

First, we configure the Qt environment and add the following line to ~/.bashrc:

export PATH=/home/xl/Qt5.9.2/5.9.2/gcc_64/bin:$PATH
export LD_LIBRARY_PATH=/home/xl/Qt5.9.2/5.9.2/gcc_64/lib:$LD_LIBRARY_PATH
export QT_PLUGIN_PATH=/home/xl/Qt5.9.2/5.9.2/gcc_64/plugins:$QT_PLUGIN_PATH
export QML2_IMPORT_PATH=/home/xl/Qt5.9.2/5.9.2/gcc_64/qml:$QML2_IMPORT_PATH

The home/xl/Qt5.9.2/5.9.2/ directory should be modified according to the Qt path installed on your computer.

Then execute sourec ~/.bashrc to make the configuration take effect.

2. Compile linuxdeployqt

Project address: https://github.com/probonopd/linuxdeployqt.git.

Although the compiled package has been released, I am using Ubuntu 18 and the system version is too high, so I still choose to compile the code.

In order to avoid the problem that the compiled package detects that our system version is too high and does not continue to execute, we comment out the following code in tools/linuxdeployqt/main.cpp before compiling:

// openSUSE Leap 15.0 uses glibc 2.26 and is used on OBS
    /*if (strverscmp (glcv, "2.27") >= 0) { //Comment version check qInfo() << "ERROR: The host system is too new.";
      qInfo() << "Please run on a system with a glibc version no newer than what comes with the oldest";
      qInfo() << "currently still-supported mainstream distribution (xenial), which is glibc 2.23.";
      qInfo() << "This is so that the resulting bundle will work on most still-supported Linux distributions.";
      qInfo() << "For more information, please see";
      qInfo() << "https://github.com/probonopd/linuxdeployqt/issues/340";
      return 1;
    }*/

Then you can use cmake and make to compile. The generated executable program is tools/linuxdeployqt/linuxdeployqt .

Finally, for ease of use, you can copy the generated executable program to the system's /usr/local/bin/ directory.

3. Packaging

Copy the Qt compiled program to a separate folder.

Then execute linuxdeployqt appname.

Generally, it will be completed smoothly. There will be an Apprun in the current directory. Just execute it directly.

But sometimes it is not so smooth, probably because the corresponding library is missing in the system. For example, the error I encountered was:

ERROR: Could not start patchelf.
ERROR: Make sure it is installed on your $PATH.
ERROR: Error reading rpath with patchelf "libQt5Widgets.so" : ""
ERROR: Error reading rpath with patchelf "libQt5Widgets.so" : ""

This error indicates that the required pathchelf tool is missing and can be solved by installing it directly:

sudo apt install patchelf

Then the following error occurred:

ERROR: ldd outputLine: "libjasper.so.1 => not found"
ERROR: for binary: "/home/xl/Qt5.9.2/5.9.2/gcc_64/plugins/imageformats/libqjp2.so"
ERROR: Please ensure that all libraries can be found by ldd. Aborting.

This shows that the libqjp2.so library is missing in our system. It's actually very strange. The local version can obviously be run, so why is this library file missing? But the solution is very simple, just install what is missing:

sudo add-apt-repository "deb http://security.ubuntu.com/ubuntu xenial-security main"
sudo apt update
sudo apt install libjasper1 libjasper-dev

After the installation is complete, it is packaged smoothly.

Summarize

The above is what I introduced to you about how to use linuxdeployqt to package Qt programs in Ubuntu. I hope it will be helpful to you. If you have any questions, please leave me a message and I will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website!
If you find this article helpful, please feel free to reprint it and please indicate the source. Thank you!

You may also be interested in:
  • How to configure the Qt development environment of the Go language on Ubuntu Linux
  • How to remotely batch execute Linux command programs using pyqt
  • A simple way to restart QT application in embedded Linux (based on QT4.8 qws)
  • How to use Qt to connect to MySQL database under ubuntu linux
  • How to install subversion 1.9.5 in Linux environment (CentOS 6.7 64-bit)
  • Solution to Linux QT Kit missing and Version empty problem

<<:  Summary of commonly used time, date and conversion functions in Mysql

>>:  Two implementations of front-end routing from vue-router

Recommend

Common array operations in JavaScript

Table of contents 1. concat() 2. join() 3. push()...

Implementation of css transform page turning animation record

Page turning problem scenario B and C are on the ...

mysql-8.0.16 winx64 latest installation tutorial with pictures and text

I just started learning about databases recently....

MySQL 5.7.30 Installation and Upgrade Issues Detailed Tutorial

wedge Because the MySQL version installed on the ...

Detailed explanation of the use of Vue mixin

Table of contents Use of Vue mixin Data access in...

Vue implements Dialog encapsulation

Table of contents Vue2 Writing Vue3 plugin versio...

Solution to Ubuntu 20.04 Firefox cannot play videos (missing flash plug-in)

1. Flash plug-in package download address: https:...

Let's take a look at some powerful operators in JavaScript

Table of contents Preface 1. Null coalescing oper...

Graphical introduction to the difference between := and = in MySQL

The difference between := and = = Only when setti...

How to execute PHP scheduled tasks in CentOS7

Preface This article mainly introduces the releva...

Detailed explanation of the use of MySQL select cache mechanism

MySQL Query Cache is on by default. To some exten...

JavaScript Objects (details)

Table of contents JavaScript Objects 1. Definitio...

A brief introduction to MySQL functions

Table of contents 1. Mathematical functions 2. St...

How to remove spaces or specified characters in a string in Shell

There are many methods on the Internet that, alth...