linux qt的编译的程序打包
1.准备好自己的库,我这里准备了一个运行的库
这里需要在自己的qt的环境中设置rpath的路径,这个是指定so的库的搜索路径,pro的指定方式
#建议使用第二种
#搜索路径是 ./
#QMAKE_LFLAGS += "-Wl,-rpath,\'\$$ORIGIN\'"
#搜索路径是 ./lib
QMAKE_LFLAGS += "-Wl,-rpath,\'\$$ORIGIN/lib\'"
#搜索路径是 ../lib
#QMAKE_LFLAGS += "-Wl,-rpath,\'\$$ORIGIN/../lib\'"
2.配置qt的路径,设置路径可以找到当前编译使用的qt的lib
#qt的路径
qtDir=/home/wl/Qt5.11.0/5.11.0/gcc_64
#check qmake exists 判断设置的路径是否正确
qmakeDir=$qtDir/bin/qmake
if [ -f "$qmakeDir" ]; then
echo "$qmakeDir exists"
else
echo "please set qtDir for example /home/qt/gcc_64"
exit 1
fi
#根据设置的qt指定特定的环境变量
export PATH=$qtDir/bin:$PATH
export LD_LIBRARY_PATH=$qtDir/lib:$LD_LIBRARY_PATH
export QT_PLUGIN_PATH=$qtDir/plugins:$QT_PLUGIN_PATH
export QML2_IMPORT_PATH=$qtDir/qml:$QML2_IMPORT_PATH
3.准备ldd大法
libsdir=$PWD/$tardir/lib
#ldd 大法
copy_dependency() {
des=$1 #获取函数的传入参数
for dep in `ldd $des | awk '{print $3}' | grep -v "("` #循环遍历
do
cp -u $dep $libsdir #拷贝到指定路径
echo "Copied dependency "$dep" to "$libsdir
done
}
copy_dependency $executable
4.qt三方库的导入
pluginsdir=$tardir/plugins
mkdir $pluginsdir
#这个是exe运行的时候会报错xcb错误的问题
qtplatformplugin=$qtDir/plugins/platforms/libqxcb.so
qtplatformplugindir=$pluginsdir/platforms
mkdir $qtplatformplugindir
echo "Created platforms directory: "$qtplatformplugindir
cp $qtplatformplugin $qtplatformplugindir
echo "Copied platform "$qtplatformplugin" to "$qtplatformplugindir
echo "Copying qtplatformplugin dependencies..."
copy_dependency $qtplatformplugin
最后的目录结构