[英]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.