How to deploy Qt applications for Linux

I have successfully completed all the steps mentioned in the Qt documentation:

Deployment But I still could not make a static Qt application, the executable generated by the steps described above still needs Qt shared objects on another system.

Any ideas?

+8
source share
2 answers

You need to deploy the application, for this I use the cqtdeployer utility

This utility itself collects all the necessary dependencies of your application, and you do not need to spend your time on this, or you can automate this process.

github (Windows)

Snapstore (Linux)

sudo snap install cqtdeployer

:

  • Windows:
%cqtdeployer% -bin myApp -qmake path/to/Qt/5.x.x/build/bin/qmake.exe -qmlDir path/to/my/qml/files/dir
  • Linux:
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)

, , . cqtdeployer

Windows, installer

+2

- :

  • LGPL , ( ) - , qt , .
  • ... .

qt -where , , , , .

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/.

libs /!

0

Source: https://habr.com/ru/post/1666892/


All Articles