To do this you need to know how to link the executable to the libraries you are distributing and which libraries to distribute.
Executable link to libraries
There are two ways to link your executable to the Qt libraries that you are distributing with your package: create a script and export the LD_LIBRARY_PATH
and change the RPATH
of executable.
Create Bash script
Way number 1 is the one that was quoted there on the site: create a script adding the directory content your libraries to the LD_LIBRARY_PATH
. Since you are distributing a program for Linux, I recommend making a Bash script. Whereas all libraries and the executable are in a directory called app
, an example script would be:
# Caminho absoluto para o diretório onde o script se encontra
# Achei esse truque no SO internacional, mas não tenho o link salvo
DIRETORIO_ATUAL="$(cd "$(dirname "$0")"; pwd)"
# Coloca o diretório com as bibliotecas no LD_LIBARY_PATH:
export LD_LIBRARY_PATH="${DIRETORIO_ATUAL}/app"
# Executa o aplicativo:
./app/aplicativo
There are plenty of great tutorials and tips on the internet about Bash on Google and in the OS itself, so do a search and you’ll be good - and post your questions here in the OS in English.
Alter RPATH
Another way to link libraries to your app is to change the RPATH
of his. The RPATH
is a list of directories inserted in the binary of its executable at build time; the ld
, which is the program that links libraries to the executable looks, among other places, at RPATH
from the app to determine where to search for libraries.
If you are using qmake, I do not recommend this method, because qmake gives a few problems to modify the RPATH
binary. If you are using Cmake (which I recommend), it is relatively simple:
set(CMAKE_INSTALL_RPATH "\$ORIGIN")
set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
Being \$ORIGIN
the directory where the executable is located. If you wanted to, for example, put all libraries in a directory called diretorio
, you would use "\$ORIGIN/diretorio"
.
Libraries required
Dependencies
It depends a lot on what you’re using, but the most basic Qt distribution in an OS like Ubuntu, for example, needs the following libraries:
libQt5Core.so.5
libQt5DBus.so.5
libQt5Gui.so.5
libQt5Widgets.so.5
libicudata.so.53
libicui18n.so.53
libicuuc.so.53
This is assuming Qt 5.4. The version of libicu*
can change depending on the version of Qt - and at this point I recommend you use Qt 5.6, which is the latest stable version and which is an extended support version.
Without the above libraries, the program doesn’t even start. If you are running on a terminal and a library that the executable depends on is missing, a message similar to this one will appear:
./aplicativo: error while loading shared libraries: libQt5Widgets.so.5: cannot open shared object file: No such file or directory
To check that all libraries that the executable depends on are present, use the ldd
.
Plugins
In addition, you also need to distribute the plugins. This is the most complicated part, because it is something that does not give problem in your machine, since it has all plugins installed and all environment variables configured, and the necessary plugins do not appear in ldd
.
You find the plugins in the folder $QTDIR/plugins
. On Linux, the minimum number of plugins you have to distribute are as follows::
platforms/libqxcb.so
platformthemes/libqgtk2.so
, if you want the application to adopt the system theme on Ubuntu and GNOME
Important to cool that directory structure of plugins must be maintained - that is, if you just play the libqxcb.so
inside your library directory, it won’t work.
Basically, that’s it. Maybe you still have to do a few more things, but doing that is kind of a trial and error process sometimes. I hope my guide will be useful!