Deploy Qt application on Linux

Viewed 2942

I have created a nice little scientific Qt application and I want to distribute it.

It was very easy to do this in Windows, I simply created a folder, put my executable there and called the windeployqt program, which put all necessary .dll files in the folder like Qt5Core.dll, Qt5Gui.dll, Qt5Charts.dll... and it created some subfolders like iconengines/, imageformats/, platforms/ and many more. All together this folder now contains 43 files. When I copy this folder to any other computer with Windows 10 it runs well.

I would like to do the same on Linux, because it is the preferred operating system that we use.

However, I struggle a bit because I do not really know how to start. Is it possible to do it the same way? Copy all necessary libraries in a folder together with the executable and simply be able to copy it on a different computer with Linux and run it? (To clarify: When I say Linux I mean Ubuntu 18.04 or 16.04)

Or is there a different way how to do it? I only have a students license so I think I'm not allowed to statically link the libraries (but I have to read the license terms again to be sure)

In case it works the same. Is there a simple way to copy all necessary libraries in this folder? Or do I have to search the 42 libraries by myself?

I have read the manual but to be honest I did not understand everything and all the example codes in there.

Thank you for your help.

2 Answers

Look at the Creating the Application Package link in the documents. For Linux, a starting script is given to you via documentation as a starting point. Here it is:

#!/bin/sh
appname=`basename $0 | sed s,\.sh$,,`

dirname=`dirname $0`
tmp="${dirname#?}"

if [ "${dirname%$tmp}" != "/" ]; then
dirname=$PWD/$dirname
fi
LD_LIBRARY_PATH=$dirname
export LD_LIBRARY_PATH
$dirname/$appname "$@"

This script must be saved as an .sh script and must live in the directory of your executable.

Make the script executable , open a terminal and do the following:

$ cd /pathToScript/
$ sudo chmod +x scriptName.sh

Then double click on your script to run.

As stated in the Qt docs this will make:

...sure that the Qt libraries will be found by the dynamic linker. Note that you only have to rename the script to use it with other applications.

If you want to statically deploy your project, you must first have a static version of Qt built from source, that can be found at this headline from the Qt Docs.

A couple more notes: If you want to distribute this project for it to be used on a Linux system. You can simply package the build folder. But to actually run it, you would need to use the script (for the easy way at least) on a Linux system. It is not necessary to go hunting for the application's dependencies.

You need to install all qt libraries first.

I think using qmake could be a solution if you're creating a Qt-based project. Qt Creator uses it as default.

qmake generates all needed files used to compile the program. Try using it.

Related