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
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:
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
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):
Or continue to modify the old method:
vi linuxdeployqt-master/tools/linuxdeployqt/main.cpp
Step 3: Use cmake configuration
cd linuxdeployqt-master
cmake CMakeLists.txt
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:
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
cmake-gui
Select the corresponding path, and then use the default unix makefile configuration:
Step 5: generate generate
Step 6: Compile make
Cut into the build directory and use the make command:
make
test program:
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/
Step 8: Test whether the compilation is successful
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
Then, find an empty directory:
It can also run on the development machine without packaging (bare metal does not work):
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
Import the environment:
Follow this process for packaging next time, and continue packaging:
(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
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:
Here is the unpackaged testDemo on bare metal:
Manually implement linuxdeployqt packaging
Step 1: Put the application in the past
(This is a development machine, it is also possible to run it directly)
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:
# Generated by linuxdeployqt
# https://github.com/probonopd/linuxdeployqt/
[Paths]
Prefix = ./
Plugins = plugins
Imports = qml
Qml2Imports = qml
At this point, we run it again:
The path is found locally.
Step 3: Realize the copy of the other three folder dependencies
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
The test machine can run:
(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
Copy it to bare metal.
Step 5: Test run on bare metal (failed)
Still fails, as follows:
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.
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
After compiling, place testDemo2 on the original deployment bare metal:
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.
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.
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)
Replace all LogError with qInfo(), as shown below:
Or not:
continue:
Tricky question:
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:
So I redid it again and used sudo to package it.
Pit 3: There is an error in relying on the link library
question
This is a conflict with the system.
The installation package is also used when compiling:
reason
No solution, there is no problem with qmake path and environment in disguise
check linuxdeployqt
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.
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.
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*
sudo linuxdeployqt testDemo -verbose2
sudo rm /usr/lib64/libQt5Core.so*
sudo linuxdeployqt testDemo -verbose2
sudo cp /home/yang/Qt5.12.8/5.12.8/gcc_64/lib/libicuuc.so* /usr/lib64/
sudo linuxdeployqt testDemo -verbose2
sudo cp /home/yang/Qt5.12.8/5.12.8/gcc_64/lib/libicudata.so* /usr/lib64/
sudo linuxdeployqt testDemo -verbose2
sudo yum install patchelf
sudo linuxdeployqt testDemo -verbose2
Yes, uos you win, I give up! ! !
Pit 4: Manual qt.conf imitation deployment or forced path switching
question
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