0

I am trying to deploy a C++ application compiled with gcc on Linux by putting the required .so files into the executable directory. I added the linker flag -Wl,-rpath=$ORIGIN so that the program may look for the linked libraries in the directory where it's located. This works so far as that all libraries that are directly linked with my executable are found (checked via ldd).

However, when I try to launch the application I get the following error:

This application failed to start because it could not find or load the Qt platform plugin "xcb".

Available platform plugins are: linuxfb, minimal, offscreen, xcb.

Reinstalling the application may fix this problem.

The platform plugins are located in the folder ./platforms (relative to the executable path). Those some other shared object files which are apparently loaded by Qt, one of them being libqxcb.so. Now, the problem is that this file again depends on libQt5Gui.so, libQt5Core.so etc. These are located in my application path, but I suspect that the libqxcb.so is somehow not able to find them there, thus it fails. Is there a possibility how I could fix this?

If I use the following script to run the application, it works (note: Ct is the name of the executable):

#!/bin/sh

DIR="$( cd "$( dirname "$0" )" && pwd )"
cd $DIR
LD_LIBRARY_PATH=LD_LIBRARY_PATH:. ./Ct

But I would like to achieve this without having to use a script to run the application.

bweber
  • 3,772
  • 3
  • 32
  • 57
  • 1
    check by 'ldd' your 'libqxcb.so', it will give you an answer on your suspicion about missed libraries. – Laser Mar 23 '16 at 05:49
  • I already did when I created the question, and as stated it is unable to find them. The question is why it doesn't find them and how I can fix that (apart from starting the application with that script). – bweber Mar 23 '16 at 17:22

1 Answers1

2

The qt deployment document is not particularly helpful with this.

The key to solving this issue is when you look at ldd output of libqxcb.so it goes in the lib folder.

libQt5Core.so.5 => <*>/plugins/platforms/./../../lib/libQt5Core.so.5 (0x00007f5f8374a000)

Therefore the directory structure should be as following:

app
|-- lib
|   |-- libQt5Core.so.5
|   |-- libQt5Gui.so.5
|   |-- libQt5DBus.so.5
|   |-- libQt5XcbQpa.so.5
|   |-- libicui18n.so.56
|   |-- libicuuc.so.56
|   `-- libicudata.so.56
|-- qt.conf
|-- app_exec
`-- plugins
    `-- platforms
        `-- libqxcb.so

In project.pro set your application rpath for lib folder:

unix:!mac{  
    QMAKE_LFLAGS += "-Wl,-rpath,\'\$$ORIGIN/lib\'"
}

Finally you need to set up qt.conf for your app to be able to find plugins (by default looks from the platforms folder):

[Paths]
Prefix=./
Libraries=lib
Plugins=plugins
user1145065
  • 268
  • 4
  • 11
  • Hey, thanks for the reply. I'll try it as soon as I've got time. What is not clear to me, is what `./bin` in the directory tree is. The executable still goes into the `app` folder, right? – bweber Oct 17 '16 at 07:17
  • 1
    Yes, sorry, that would be the executable, qt.conf has to be in the same directory as your executable http://doc.qt.io/qt-5/qt-conf.html – user1145065 Oct 17 '16 at 08:21
  • Thanks, works like a charm. The essential part was the `qt.conf` file with the `Libraries=...` line. As a result also the shared object files that are loaded as a plugin find their dependencies. – bweber Oct 20 '16 at 10:58
  • What I just wanted to add: I use CMAKE instead of QMAKE. There the command for adding the compiler flags looks a bit different: `set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wl,-rpath='$ORIGIN/lib'")` – bweber Oct 29 '16 at 08:38