我按照 Qt 文档中提到的步骤成功完成了以下操作:
但是,我仍然无法生成静态 Qt 应用程序,由上述文档步骤生成的可执行文件在其他系统上仍然需要 Qt 共享对象。
有什么想法吗?
我按照 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.x.x/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
export LD_LIBRARY_PATH=<path-to-libs>
以便找到库...或将库安装到类似于 /usr/lib/your-appplication/
的位置中。但是,安装库是另一个问题/主题!cqtdeployer
看起来可能是要使用的工具 - 但在我编写这个脚本时它还不存在(至少我不知道)- 它看起来做得很好,但我没有使用过。不过,如果你想要一种轻量级的方式,这对我来说已经足够好了:) - code_fodder
-static
标志构建 Qt 本身之后,你确定你的应用程序已使用正确的 Qt 版本构建,并且静态库已链接吗? - SingerOfTheFall