[英]How to deploy Qt applications for Linux
我成功地按照 Qt 文档中提到的所有步骤进行了操作:
但是我仍然无法制作静态Qt应用程序,上述文档步骤生成的可执行文件仍然需要其他系统上的Qt共享对象。
有任何想法吗?
您需要部署应用程序,为此我使用实用程序cqtdeployer
此实用程序本身会收集应用程序的所有必要依赖项,您无需花费时间,或者您可以自动执行此过程。
您可以从github版本安装 (Windows)
要么
来自snapstore (Linux)
sudo snap install cqtdeployer
您可以按如下方式使用:
%cqtdeployer% -bin myApp -qmake path/to/Qt/5.x.x/build/bin/qmake.exe -qmlDir path/to/my/qml/files/dir
cqtdeployer -bin myApp -qmake path/to/Qt/5.x.x/build/bin/qmake -qmlDir path/to/my/qml/files/dir
path/to/Qt/5.xx/build/bin/qmake - 这是使用 qmake 构建程序的方式。
path/to/my/qml/files/dir - 这是直接指向您的 qml 文件(您编写的)的路径
并使用 sh 脚本 (Linux) 或 exe (Windows) 运行应用程序
如果您需要使用 Windows 版本,只需从安装程序安装应用程序
如果您想为您的应用程序创建一个简单的安装程序,只需为cqtdeployer的命令添加qif选项。 例子 :
cqtdeployer -bin myApp -qmake path/to/Qt/5.x.x/build/bin/qmake -qmlDir path/to/my/qml/files/dir qif
有关 cqtdeployer 的所有复杂功能的详细信息可以在官方wiki项目中找到。
部署应用程序的最佳方式不一定是静态链接它,原因如下:
安装 qt-everywhere 也不是很好,我只是不知道您如何保证这些库与您的程序需要的库版本相同。
所以我开始做的是创建我自己的脚本来为我部署 qt。 基本的“jist”是您使用ldd
找出您需要的 qt 库,并将它们复制到与可执行文件相同的文件夹中的子文件夹 ( ./lib
) 中,以制作安装包。
注意:在 Windows 上有一个 deployqt 应用程序,它做类似的事情(记不清它叫什么了)。
下面我复制了我的部署脚本的一个版本。 请注意,它现在已经很老了,但我不明白为什么它不能工作(它写得不是特别好),但如果不是,它会给你一个起点。 还要注意插件的。 在这个脚本中,我添加了代码来复制音频插件,因为我正在使用它。 如果您正在使用其他插件,那么您将需要复制这些插件(它们通常位于 qt 库的子目录中,例如 .../audio)...我有一个待办事项来尝试从 . pro 文件,但我从来没有考虑过(我也必须将 .pro 文件传递给这个脚本)......
要运行,只需运行此脚本并传入可执行文件所在的目录。
#!/bin/bash
# Rememeber start dir
START_DIR=$PWD
# Determine which dir to deploy in and cd to that dir
if [ -d "$1" ]; then
DEPLOY_DIR=$1
else
DEPLOY_DIR=$PWD
fi
echo "Deploy dir: $DEPLOY_DIR"
cd $DEPLOY_DIR
# Run ldd on all files in the directory and create a list of required qt libs
flag=false
for entry in `ldd $DEPLOY_DIR/* | grep -i qt`; do
if $flag; then
# Only add to the array if it is not already in it
if ! [[ $libsArray =~ $entry ]]; then
echo "adding $entry"
libsArray="$libsArray $entry"
fi
flag=false
fi
# If we see a "=>" then the next line will be a library
if [ $entry == "=>" ]; then
flag=true
fi
done
echo
echo
# Create the required folder structure. Note here we are need the qt audio plugin so we are going to manually copy that as well.
mkdir -p lib
mkdir -p lib/audio
# Now copy these files to the deploy directory
for entry in $libsArray; do
echo "cp -v -f $entry $DEPLOY_DIR/lib"
cp -v -f $entry $DEPLOY_DIR/lib
done
# Now get the audio lib - this is a plugin that we are using so we need these libs as well.
# Add other plugins here as well.
# TODO: maybe we can read this in from the *.pro file.
cp -v -f `qmake -query QT_INSTALL_BINS`/../plugins/audio/* $DEPLOY_DIR/lib/audio
# Go back to start dir
cd $START_DIR
拥有所需的所有文件后,您应该能够将整个文件复制到另一台 PC 并运行它。 注意:您可能必须设置export LD_LIBRARY_PATH=<path-to-libs>
以便可以找到库...或将库安装到诸如/usr/lib/your-appplication/
。
但是安装库是另一个问题/主题!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.