Qt5 Deploy on Linux - No installation

3

I'm developing a solution in QtCreator Qt version 5.4.2. Well, I have the following problem: When I run on my machine and on any Ubuntu Vivid (15.04) it works. But when I try to run in Ubuntu 14.04 LTS gives error. There are ways to make this application work across multiple distros. From what I researched the best is:

You can write a startup script for your application, where you modify the dynamic linker configuration (e.g., adding your application's directory to the LD_LIBRARY_PATH environment variable. Source Site

I just can not figure out how to do this or the script. I need this application to work without being .deb, ie without having to be installed and without the user having to install anything for it to work. Can anyone who works with QT help me? Att

    
asked by anonymous 17.06.2015 / 03:32

1 answer

1

To do this you need to know how to link the executable to the libraries you are distributing and what libraries to distribute.

Linking executable to libraries

There are two ways to link your executable to the Qt libraries you are distributing with your package: create a script and export the LD_LIBRARY_PATH and change the RPATH of the executable.

Create Bash script

Way number 1 is what was quoted there on the site: create a script by adding the directory content your libraries to LD_LIBRARY_PATH . Since you are distributing a program for Linux, I recommend doing a Bash script. Since all libraries and the executable are in a directory named 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 lots of great tutorials and tips on the internet about Bash on Google and on the OS itself, so check it out for yourself - and post your questions here in the Portuguese OS.

Change% with%

Another way to link libraries to your application is to change the RPATH of it. RPATH is a list of directories inserted in the binary of your executable at compile time; %, which is the program that links the libraries to the executable looks, among other places, in the RPATH of the application to determine where to look for libraries.

If you are using qmake, I do not recommend this method, since qmake gives you a few problems to modify the ld of the binary. If you're using CMake (which I recommend), it's relatively simple:

set(CMAKE_INSTALL_RPATH "\$ORIGIN")
set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)

Being RPATH the directory where the executable is. If you wanted to, for example, put all the libraries in a directory called RPATH , you would use \$ORIGIN .

Necessary libraries

Dependencies

Depends heavily on what you are using, but the more basic distribution of Qt into an OS such as Ubuntu requires the following libraries:

  • diretorio
  • "\$ORIGIN/diretorio"
  • libQt5Core.so.5
  • libQt5DBus.so.5
  • libQt5Gui.so.5
  • libQt5Widgets.so.5
  • libicudata.so.53

That's assuming Qt 5.4. The version of libicui18n.so.53 can change depending on the version of Qt - and, at that point, I recommend you use Qt 5.6, which is the last stable version and which is an extended support version.

Without the above libraries, the program will not start. If you are running on a terminal and a library that the executable depends on is missing, a message like this will appear:

./aplicativo: error while loading shared libraries: libQt5Widgets.so.5: cannot open shared object file: No such file or directory

To verify that all libraries that the executable depends on are present, use libicuuc.so.53 .

Plugins

In addition, you also need to distribute the plugins. This is the most complicated part, because it is not a problem on your machine, since it has all the installed plugins and all environment variables configured, and the required plugins do not appear in libicu* .

You find the plugins in the ldd folder. On Linux, the minimum of plugins you have to distribute are the following:

  • ldd
  • $QTDIR/plugins , if you want the application to adopt the system theme in Ubuntu and GNOME

It's important to note that the plugins directory structure should be maintained - that is, if you just play platforms/libqxcb.so within the directory of your libraries, it will not work.

Basically, this is it. Maybe you still have to do a few more things, but doing this is kind of a trial and error process sometimes. I hope my guide is helpful!

    
22.04.2016 / 03:05