Qt executable program packaging under windows/linux, double-click the sh script to run the program on the linux desktop

1. Qt packaging under windows

The packaging of Qt executable files under windows is simply to use the packaging tool windeployqt that comes with Qt to package. This tool exists in the Qt installation directory, and the execution command is: windeployqt name.exe

For packaging dependent files, please refer to steps 1-7 in the link below. The following steps are the process of packaging dependent files as installation packages: 

The Qt program is packaged and released, including third-party libraries and detailed tutorials. _Fragrant and delicious mandarin blog-CSDN blog_qt program packaging

 To package the executable file as an installation package, please refer to the link:

NSIS packaging tool usage introduction and NSIS related software download

2. Qt relies on file packaging under linux, and writes a desktop double-click to run the program sh script

 (1) Use QtCreator to create a Qt demo project, select the release mode, and generate the executable file untitled1 as follows:

(2) Copy the executable file untitled1 to the package file path packDir, as follows:

(3) Use the ldd command to package the execution file dependent files into the file, and write the script as follows:

#!/bin/bash
#S1打包的文件路径,$2可执行文件名
#package.sh打包脚本位于打包文件上一级目录,  eg:bash package.sh $PWD/packDirName untitled1
#$2"_lib_detail".txt 文件保存依赖文件详细情况

PACKAGE_Dir=$1
EXE_Name=$1/$2

dependlib_arr=($(ldd $EXE_Name | grep -o "/.*" | grep -o "/.*/[^[:space:]]*"))

ldd $EXE_Name | grep -o "/.*" | grep -o "/.*/[^[:space:]]*">$2"_lib_detail".txt 
num=0
for varlib in ${dependlib_arr[*]}
do
    cp "$varlib" $PACKAGE_Dir
    #echo $varlib
    let num+=1
done
echo "$2 of the dependency lib num is ${num}"
echo "Check the $2"_lib_detail".txt for details"


#ldd $EXE_Name输出依赖库
#grep -o "/.*" 只显示匹配的内容
#grep -o "/.*/[^[:space:]]*" 提取不包含空格的内容

The packaging script is located one layer above the packaging file packDir, as follows:

 (4) Run the packaging script

 The above running results indicate that the executable file depends on 25 library files, and the details of the dependent file names are recorded in untitled1_lib_detail.txt.

Package the result if needed:

 The above packaging dependent scripts refer to: Packaging, running, and closing program tutorials of QT programs under Linux_linux qt_Be a strong female man's blog-CSDN blog

(5) Write the running program script file run.sh on the desktop, as follows:

Note that the script file attribute needs to be set to executable attribute, the command is $chmod +x run.sh, as follows:

 Double-click the script run.sh to run the program, as follows:

Guess you like

Origin blog.csdn.net/hanxiaoyong_/article/details/128997784