Qt, Linux, GCC: -Wl, -rpath = $ ORIGIN does not work for xcb platform plugins

I am trying to deploy a C ++ application compiled with gcc on Linux by putting the necessary .so files in an executable directory. I added the linker flag -Wl,-rpath=$ORIGIN so that the program can search for linked libraries in the directory in which it was located. This works until all the libraries that are directly linked to my executable file (checked via ldd) are found.

However, when I try to start 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. 

Platform plugins are located in the ./platforms folder (relative to the executable path). Those are some other common object files that Qt obviously loads, one of which is libqxcb.so . The problem is that this file again depends on libQt5Gui.so , libQt5Core.so , etc. They are located in my application path, but I suspect that libqxcb.so somehow cannot find them, so it fails. Is there any way I can fix this?

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

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

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

0
source share
1 answer

The qt deployment document does not particularly help with this.

The key to solving this problem is to view the ldd output of libqxcb.so , which is located in the lib folder.

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

Therefore, the directory structure should be as follows:

 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, install the rpath application for the lib folder:

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

Finally, you need to configure qt.conf for your application to be able to find plugins (looks from the platforms folder by default):

 [Paths] Prefix=./ Libraries=lib Plugins=plugins 
+1
source

Source: https://habr.com/ru/post/1238190/


All Articles