table of Contents
Ready to work
1. Generate executable file
qt using Release mode to compile
[sometimes this file is not generated after compilation, you need to add a sentence in the pro file: QMAKE_LFLAGS += -no-pie]
2. Create a new folder
Create a new folder "qt_ctrl" on the desktop
3. Create a new .sh file
Create two new .sh files in the folder "qt_ctrl"
copylib.sh // Used to find lib files
#!/bin/bash
LibDir=$PWD"/lib"
Target=$1
lib_array=($(ldd $Target | grep -o "/.*" | grep -o "/.*/[^[:space:]]*"))
$(mkdir $LibDir)
for Variable in ${lib_array[@]}
do
cp "$Variable" $LibDir
done
untitled.sh //Same name as the packaged executable file, used for running on another platform
#!/bin/sh
appname=`basename $0 | sed s,\.sh$,,`
dirname=`dirname $0`
tmp="${dirname#?}"
if [ "${dirname%$tmp}" != "/" ]; then
dirname=$PWD/$dirname
fi
LD_LIBRARY_PATH=$dirname
export LD_LIBRARY_PATH
$dirname/$appname "$@"
4. Find the platforms folder in the
qt installation directory Find the platforms folder in the qt installation directory, and copy it to the folder "qt_ctrl".
The path of the platforms folder of the editor is: /usr/lib/x86_64-linux-gnu/qt5/plugins/platforms The
installation method is different, the path may be different, some are in home, some are in opt. . .
(You can also refer to the path: ~/Qt5.9.5/5.9/gcc_64/plugins/platforms)
Find the lib file
1. Put copylib.sh in the directory where the executable file is located : (build-untitled-unknown-Release)
and execute:
chmod 777 copylib.sh
./copylib.sh untitled //untitled改成自己的可执行文件名
After execution, a lib folder
will be generated. Copy all the files in this lib folder to the folder "qt_ctrl".
Copy the executable file "untitled" to the folder "qt_ctrl".
2. Put copylib.sh into the qt_ctrl/platforms directory
Then execute:
chmod 777 copylib.sh
./copylib.sh libqxcb.so
Similarly, there will be an extra lib folder in the platforms directory.
Copy all the files in this lib folder to the folder "qt_ctrl".
At this point, all lib files have been prepared. . .
Cross-platform operation
Copy the "qt_ctrl" folder to the ubuntu system of another computer to run it.
Note: You cannot run the executable file directly when it is running, you need to run the .sh file with the same name (untitled.sh)
chmod -R 777 untitled.sh
./untitled.sh
The first error is easy to report : Permission denied
/home/chenxd/qt_ctrl/untitled.sh: 12: /home/chenxd/qt_ctrl/untitled.sh: /home/chenxd/qt_ctrl/untitled: Permission denied
Solve :
sudo chmod -R 777 /home/chenxd/qt_ctrl
sudo chmod -R 777 /home/chenxd/qt_ctrl/untitled.sh
/home/chenxd/qt_ctrl/untitled.sh
(Note to change to your own file path)
[After running, go directly to the directory where untitled.sh is located, and execute:
./untitled.sh ] (Internet rumors) [The editor found that when "./untitled.sh" is successfully executed for the first time, double-click the executable file The icon can also be run directly, copy it to the desktop, or double-click to run, which is a lot more convenient] ( Xiaobian pro test )
(The packaged file of the project: https://download.csdn.net/download/xx970829/15992965)
**Reference link: **https://blog.csdn.net/z3512498/article/details/64922180