2

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.

user7431005
  • 3,899
  • 4
  • 22
  • 49
  • 1
    On linux you would not package `Qt` binaries with your application. You would instead have the requirement that a certain version of `Qt` is installed on the system. Usually this means using the official distribution package manager for the install of the dependencies. – drescherjm Sep 16 '18 at 21:17
  • Maybe you want this (i have not used it ever): https://doc.qt.io/qtinstallerframework/ifw-overview.html – drescherjm Sep 16 '18 at 21:33

2 Answers2

1

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.

GKE
  • 960
  • 8
  • 21
  • 1
    Thank you for your detailed answer! I have created the script and when I run it the software opens. But it only works in the build directory (where all the *.o files and the *.h and *.cpp files are stored) As soon as I copy the executable and this script into a different folder it doesn't work. What else should be in this directory? According to the Qt Docs and their example you also need to add the libQt5Core.so.5 and libQt5Gui.so.5... files in the directory. – user7431005 Sep 17 '18 at 07:53
  • You might want to [make a symlink](https://stackoverflow.com/questions/9104337/create-a-symbolic-link-of-directory-in-ubuntu) of the script to another directory. – GKE Sep 17 '18 at 07:58
  • Here is another [post](https://stackoverflow.com/questions/1951742/how-to-symlink-a-file-in-linux) that can show you how to make a symlink. – GKE Sep 17 '18 at 08:04
-2

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.

hearot
  • 124
  • 9