Tongxin UOS system development notes (7): Use linuxdeployqt to release qt programs on Tongxin UOS system

If the article is an original article, please indicate the source of the original article when reprinting.
The blog address of this article: https://hpzwl.blog.csdn.net/article/details/131411975

Red Fatty (Red Imitation)'s Blog Encyclopedia: Development technology collection (including Qt practical technology, Raspberry Pi, 3D, OpenCV, OpenGL, ffmpeg, OSG, single-chip microcomputer, combination of software and hardware, etc.) is continuously being updated... (click on the portal)

Development of domestic Kylin system and Tongxin UOS system

Previous: " Union UOS System Development Notes (6): After extracting the online installation software, extract its installation package, and deploy the target machine to install the software using an offline software package" Next
: " Union UOS System Development Notes (8) ): Compile and build the mqtt basic environment on Tongxin UOS (the version uses QMQTT::Clinet)


foreword

  Publishing the qt program on ubuntu is relatively good, using scripts, but when it is released on Tongxin UOS Kylin, because of different versions such as Galaxy Kylin, using scripts is not compatible. At the same time, in order to achieve the effect of directly clicking the application to start the application, Use linuxdeployqt to release qt programs.


Notice

  In this article, the manual combination of several methods was finally successful, and it took a lot of time to research. It was inferred that the terminal directly entered an additional environment variable after ldd, resulting in the failure to connect successfully, that is, the first layer was successful, and the first The environment variable of this step that the library of the layer calls ldd depends on is strengthened.
  But in the end, the packaged deployment was realized by manually implementing linuxdeployqt and compiling configuration.


related blog

  " Qt practical skills: ubuntu release program packaging process (solve plug-in xcb loading failure) "
  " About the QWidget+Qml program packaged to ubuntu, the program is different from the system library version, and the method of adding and relying on the built-in library when compiling "
  " Qt Practical Tips: Use linuxdeployqt to package and release qt programs on CentOS "
  " Kylin System Development Notes (8): Use linuxdeployqt to release qt programs on domestic Kylin systems "


Tongxin UOS system version

  system version:
  insert image description here


linuxdeployqt

The Linux deployment tool linuxdeployqt takes an application as input and makes it self-contained   by copying the resources used by the application, such as libraries, graphics, and plugins, into a package . The resulting package can be distributed to users as an AppDir or AppImage, or put into a cross-distribution package. It can deploy applications written in C, C++, and other compiled languages ​​in systems such as CMake, qmake, and make as part of the build process. When used in a Qt-based application, it can bind a specific minimum subset of Qt required to run the application.

Source code download address

  csdn fans 0 point download address: https://download.csdn.net/download/qq21497936/86803960
  gitcode address: https://gitcode.net/mirrors/probonopd/linuxdeployqt


linuxdeployqt compilation (Union UOS system)

Step 1: Download and decompress

  insert image description here

Step 2: Modify the source code and remove the gcc version check

  Find the source code of main.cpp, and comment out this section (about line 192) (here, by looking at the source code, it can actually be controlled through configuration (found by researching the source code, but we don’t act anymore, just post it):
  insert image description here

  Or continue to modify the old method:

vi linuxdeployqt-master/tools/linuxdeployqt/main.cpp

  insert image description here

Step 3: Use cmake configuration

cd linuxdeployqt-master
cmake CMakeLists.txt

  insert image description here

  Because the installation of git may be wrong with this project, we directly use the source code to modify Dafa, directly locate the code and delete it:

vi CMakeList.txt

  Directly delete the cache file in the directory: CMakeCache.txt, and then continue:
  insert image description here

  continue cmake CMakeList.txt

Step 4: Configure Qt's dependent environment

  The Kirin system itself comes with a qt5 library (without development-related libraries), and we use an additionally installed qt5, so the dependency needs to be introduced into the qt5 we installed ourselves.
  In order to facilitate configuration and not affect the system, we install the gui version of cmake:

sudo yum install cmake-gui

  insert image description here

  insert image description here

cmake-gui 

  Select the corresponding path, and then use the default unix makefile configuration:
  insert image description here

  insert image description here

  insert image description here

Step 5: generate generate

  insert image description here

Step 6: Compile make

  Cut into the build directory and use the make command:

make

  insert image description here

  test program:
  insert image description here

Step 7: Install to the system directory

  Without make install this, manually move to /usr/local/bin

sudo cp tools/linuxdeployqt/linuxdeployqt /usr/local/bin/

  insert image description here

Step 8: Test whether the compilation is successful

  insert image description here


linuxdeployqt packaging process (arm can see, this pc version failed)

  (PS: After the virtual machine is packaged, return to the bare metal version and test again)
  Create a new project
  insert image description here

  Then, find an empty directory:
  insert image description here

  It can also run on the development machine without packaging (bare metal does not work):
  insert image description here

  Here to introduce Qt into the environment, in order not to affect the system, use the source script to import, and use source env.sh to import before each use.

touch env.sh

  Then enter the following (QT_DIR is the path where Qt is installed):

#!/bin/sh
QT_DIR=/home/yang/Qt5.12.8/5.12.8/gcc_64

export PATH=${QT_DIR}/bin:$PATH
export LIB_PATH=${QT_DIR}/lib:$LIB_PATH
export PLUGIN_PATH=${QT_DIR}/plugins:$PLUGIN_PATH
export QML2_PATH=${QT_DIR}/qml:$QML2_PATH
export LD_LIBRARY_PATH=${QT_DIR}/lib:$LD_LIBRARY_PATH

echo $PATH
echo $LIB_PATH
echo $PLUGIN_PATH
echo $QML2_PATH
echo $LD_LIBRARY_PATH

  insert image description here

  Import the environment:
  insert image description here

  Follow this process for packaging next time, and continue packaging:
  insert image description here

  (PS: There is no packaging with sudo here, and the permission control may be stricter, see " Entering the Pit 2 ")
  The following uses sudo to package:

sudo linuxdeployqt testDemo -verbose2

  insert image description here

  The above is that the Qt5Widget library is connected to the system library, the version is different, and the api cannot be found.
  The following is the unpackaged testDemo on the development machine:
  insert image description here

  Here is the unpackaged testDemo on bare metal:
  insert image description here


Manually implement linuxdeployqt packaging

Step 1: Put the application in the past

  insert image description here

  (This is a development machine, it is also possible to run it directly)
  insert image description here

Step 2: Create qt.conf

  This file is the most important. When calling the testDemo application, it loads first and then searches for the configuration of the library path. Without it, it will go to the system environment variables.

touch qt.conf
vi qt.conf

  The content is copied from the file packaged by another domestic Kirin, as follows:
  insert image description here

# Generated by linuxdeployqt
# https://github.com/probonopd/linuxdeployqt/
[Paths]
Prefix = ./
Plugins = plugins
Imports = qml
Qml2Imports = qml

  At this point, we run it again:
  insert image description here

  The path is found locally.

Step 3: Realize the copy of the other three folder dependencies

  insert image description here

ls -l
cp /home/yang/Qt5.12.8/5.12.8/gcc_64/translations/ . -rf
cp /home/yang/Qt5.12.8/5.12.8/gcc_64/plugins/ . -rf
cp /home/yang/Qt5.12.8/5.12.8/gcc_64/lib/ . -rf
ls -lh

  insert image description here

  The test machine can run:
  insert image description here

  (PS: here are all copied libraries, no dependency clipping, no matter for now, it takes much longer than expected)

Step 4: Pack and put on the bare metal

  Because there is no cropping, the package is relatively large:

cd ..
tar cvf outManual.tar outManual
ls -l outManual.tar

  insert image description here

  Copy it to bare metal.
  insert image description here

  insert image description here

Step 5: Test run on bare metal (failed)

  Still fails, as follows:
  insert image description here

  This is still the same as before, libQt5Widget.so.5 depends on libQt5Core.so.5, the current configuration is used in front, and then the dependent library of the library is forced to be imported into /usr/lib64 , which is the same problem as the previous linuxdeployqt packaging.
  insert image description here

  Then I had an idea, so I tried to add the LD_LIBRARY_PATH test, and it can run successfully. See " Pit 4 " for details.

Step 6: Introduce runtime path pro configuration QMAKE_RPATHDIR when compiling

  In order not to add additional environment variables at runtime, and to avoid xcb problems in packaging , you have to modify the .pro file as shown below:

# 这里是添加运行应用的时候的运行包,此处避免额外设置LD_LIBRARY_PATH
QMAKE_RPATHDIR = ./lib

  insert image description here

  After compiling, place testDemo2 on the original deployment bare metal:
  insert image description here
  finally, click directly to run successfully.


into the pit

Pit 1: Compiling linuxdeployqt depends on the Qt path problem

question

  When starting to compile, let it depend on the system, which directly leads to the fact that even if other qt environment variables are introduced, the packaging is also dependent on the system, and it is not packaged directly.
  insert image description here

reason

  It is suspected that it is related to the dependency of compiling linuxdeployqt, so redo the cmake to install Qt by yourself.

solve

  Redo it and compile it after installing Qt's cmake, it is still the same.
  insert image description here

Entry 2: The problem that linuxdeployqt does not copy

question

  As in the previous entry, it is not copied, and it has nothing to do with compilation dependencies.

try

  There is no way, directly dry the source code of linuxdeployqt's main.cpp:
  1. First debug where there is no print, after each modification of the source code and recompile, deploy and then package to see the output result. (PS: It is found that qDebug() does not output, but qInfo() is output)
  insert image description here

  insert image description here

  insert image description here

  Replace all LogError with qInfo(), as shown below:
  insert image description here

  insert image description here

  Or not:
  insert image description here

  continue:
  insert image description here

  Tricky question:
  insert image description here

  So far, it can be confirmed that it is a compatibility problem. This problem is more difficult and cannot be adjusted in the short term.

solve

  The Linuxdeployqt method has not been solved yet. You can change the version of linuxdeployqt. Maybe different uos versions will not have this problem again. It is strange that even LogError and qDebug do not come out.
  Follow-up, the next day I suddenly thought of whether sodu permission is needed, tried it, and it was indeed:
  insert image description here

  So I redid it again and used sudo to package it.

Pit 3: There is an error in relying on the link library

question

  insert image description here

  This is a conflict with the system.
  The installation package is also used when compiling:
  insert image description here

reason

  insert image description here

  insert image description here

  No solution, there is no problem with qmake path and environment in disguise
  insert image description here

  check linuxdeployqt
  insert image description here

try 1

  Take a snapshot, then delete all /usr/lib64/Qt5* in the directory, first check whether the system is enabled normally, and then try to pack it.

sudo rm /usr/lib64/libQt5*

  Restart, indeed, the system can't start, the system depends on the library under Qt5.11.
  insert image description here

  So it cannot be deleted, this way is dead.

try 2

  Take a snapshot, then copy the installed Qt5 library, first check whether the system is enabled normally, and then try to package it.
  Execute the copy command, and the screen will be black immediately. This way is different.
  Therefore, the library under /usr/lib64 cannot be moved.
  insert image description here

  It is suspected here that a fixed priority environment variable has been entered since entering the terminal. It is only speculated that linuxdeployqt is currently taking another half a day, and there is still no solution for the time being.

Solution (a bit biased, failed)

  If you can’t find a library, delete a library. At this time, the system has loaded the library into the memory to run, and it will not affect the running system, but it cannot be restarted, as follows:

sudo linuxdeployqt testDemo -verbose2
sudo rm /usr/lib64/libQt5Gui.so*

  insert image description here

  insert image description here

sudo linuxdeployqt testDemo -verbose2
sudo rm /usr/lib64/libQt5Core.so*

  insert image description here

sudo linuxdeployqt testDemo -verbose2
sudo cp /home/yang/Qt5.12.8/5.12.8/gcc_64/lib/libicuuc.so* /usr/lib64/

  insert image description here

sudo linuxdeployqt testDemo -verbose2
sudo cp /home/yang/Qt5.12.8/5.12.8/gcc_64/lib/libicudata.so* /usr/lib64/

  insert image description here

sudo linuxdeployqt testDemo -verbose2
sudo yum install patchelf
sudo linuxdeployqt testDemo -verbose2

  insert image description here

  insert image description here

  Yes, uos you win, I give up! ! !

Pit 4: Manual qt.conf imitation deployment or forced path switching

question

  insert image description here

reason

  Analyzing the system’s second search for the library, it will always be imported into /usr/lib64. This problem is very annoying. From the beginning, linuxdeployqt cannot be packaged. This is the root cause.

solve

  When compiling directly, the most preferred way is to let the application rely on the relative path when running, instead of relying on the environment variables and configuration files at runtime.
  Pro joins the configuration file:

# 这里是添加运行应用的时候的运行包,此处避免额外设置LD_LIBRARY_PATH
QMAKE_RPATHDIR = ./lib

  When you click the application luck, the application itself will first rely on the library search under ./lib.


Previous: " Union UOS System Development Notes (6): After extracting the online installation software, extract its installation package, and deploy the target machine to install the software using an offline software package" Next
: " Union UOS System Development Notes (8) ): Compile and build the mqtt basic environment on Tongxin UOS (the version uses QMQTT::Clinet)


If the article is an original article, please indicate the source of the original article when reprinting.
The blog address of this article: https://hpzwl.blog.csdn.net/article/details/131411975

Guess you like

Origin blog.csdn.net/qq21497936/article/details/131411975