工作小计 QT打包
qt的程序调试好了后,如果需要发给其他人,需要连带库等文件一起打包
需要工具linuxdeployqt,源码编译好后,加入可执行路径
版本报错就高版本运行linuxdeployqt,注释掉部分代码即可
linuxdeployqt XXX -no-strip
#-no-strip会使得文件变大,保留更多的信息
执行完毕后,发现多了qt.conf文件和lib plugins translations三个文件夹
---bin
---xxx
---qt.conf
---lib
---plugins
---translations
可以看到qt.conf把依赖文件都生成好放入了对应的文件夹中
# Generated by linuxdeployqt
# https://github.com/probonopd/linuxdeployqt/
[Paths]
Prefix = ../
Plugins = plugins
Imports = qml
Qml2Imports = qml
Libraries = lib
此时可以直接执行以下xxx文件,发现报错缺少qt的部分组件,qml没有找到。将qt对应的qml文件夹拷贝到当前目录
cp /home/test/Qt/5.15.2/gcc_64/qml ./ -r
如果仍然缺少文件,把ldd需要链接的文件全给他链接过去,执行copylib.sh xxx
#!/bin/sh
bin=$1 #发布的程序名称
desDir="../lib" #你的路径,在这里就是上一级目录里的lib
if [ ! -d $desDir ];then
#echo "makedir $desDir"
mkdir $desDir
fi
libList=$(ldd $bin | awk '{if (match($3,"/")){ printf("%s "),$3 } }')
cp $libList $desDir
启动脚本搞一下,链接上对应的库
PWD=`pwd`
export LD_LIBRARY_PATH=${PWD}/lib:$LD_LIBRARY_PATH
nohup ./bin/xxx&
打包
zip pkg.zip ./bin/ ./translations/ ./qml/ ./lib ./plugins/ run.sh -r
收到包后执行run.sh即可
qt相关的bashrc设置
#run qt
export QT_DIR=~/Qt/5.15.2/gcc_64/
export Qt5_DIR=~/Qt/5.15.2/gcc_64/
#qtdeploy
export QTDIR=~/Qt/5.15.2
export PATH=${QTDIR}/gcc_64/bin:~/Qt/Tools/QtCreator/bin:~/Qt/Tools/QtDesignStudio/bin:$PATH
export LD_LIBRARY_PATH=${QTDIR}/gcc_64/lib:~/Qt/Tools/QtCreator/lib/Qt/lib/:$LD_LIBRARY_PATH
export QML_IMPORT_PATH=${QTDIR}/gcc_64/qml
最终的打包脚本
#!/bin/bash
FILE=qt.conf
QML_DIR=/home/zyx/Qt/5.15.2/gcc_64/qml
BIN_NAME=test
EXI_LIB=/home/zyx/extlib
linuxdeployqt $BIN_NAME -no-strip
if [ -f "$FILE" ]; then
echo "$FILE exist"
else
echo "ERROR $FILE does not exist"
exit 1
fi
echo "Libraries = lib" >> $FILE
echo "step1: linuxdeployqt"
cd ..
cp $QML_DIR ./ -r
cd -
desDir="../lib"
if [ ! -d $desDir ];then
echo "makedir $desDir"
mkdir $desDir
fi
libList=$(ldd $BIN_NAME | awk '{if (match($3,"/")){ printf("%s "),$3 } }')
cp $libList $desDir
echo "step2: collect so"
cd ..
cp $EXI_LIB/* ./lib -r -n
echo "step3: collect extlib"
cat>run.sh<<EOF
PWD=\`pwd\`
export LD_LIBRARY_PATH=\${PWD}/lib:\$LD_LIBRARY_PATH
cd bin
./$BIN_NAME
EOF
chmod 777 run.sh
echo "step4: gen run.sh"
zip pkg.zip ./bin/ ./translations/ ./qml/ ./lib ./plugins/ run.sh -r
echo "step5: gen pkg.zip"