Solve the problem of packaging Qt programs with linuxdeployqt under Ubuntu

  • 2021-06-28 09:55:09
  • OfStack

Write some Qt interface programs, but find it difficult to migrate to other computers without Qt installed.Looking at the data, we know that there are windowsdeployqt programs on windows and linuxdeployqt on linux can help us package quickly.

1. Configure the Qt environment

First, we configure the Qt environment to include in ~/.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

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

Then execute sourec ~/.bashrc Make the configuration effective.

2. Compile linuxdeployqt

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

Although I released the compiled package, I chose to compile the code because I was using Ubuntu18 and the system version was too high.

To avoid the compiled package runtime detecting that our system version is too high to continue execution, we will tools/linuxdeployqt/main.cpp The following code in is commented out:


// 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;
    }*/

You can then compile using cmake and make.The generated executable is tools/linuxdeployqt/linuxdeployqt .

Finally, for ease of use, the generated executable can be copied to the system's /usr/local/bin/ Catalog.

3. Packaging

Copy the Qt compiled program into a separate folder.

Then execute linuxdeployqt appname.

1 Usually it will be completed smoothly. There will be an Apprun in the current directory, which can be executed directly.

But sometimes it is not so smooth, it should be that there are no libraries 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 is an indication that the required pathchelf tools are missing and can be resolved by direct installation:

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 indicates that the library libqjp2.so is missing from our system.In fact, it's strange why the library file is still missing because the local people can already run.But the solution is simple: load whatever is missing:


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

Once the installation is complete, the package is ready.

summary


Related articles: