Qt,Linux,GCC:-Wl,-rpath = $ ORIGIN不适用于平台插件xcb [英] Qt, Linux, GCC: -Wl,-rpath=$ORIGIN not working for platform plugin xcb
问题描述
我试图通过将所需的.so文件放入可执行文件目录来在Linux上部署一个使用gcc编译的C ++应用程序。我添加了链接器标记 -Wl,-rpath = $ ORIGIN
,以便程序可以在它所在的目录中查找链接库。这个工作到目前为止,所有与我的可执行文件直接链接的库都被发现(通过ldd检查)。
但是,当我尝试启动应用程序时,以下错误:
此应用程序无法启动,因为它无法找到或加载Qt平台插件xcb。
可用的平台插件是:linuxfb,minimal,offscreen,xcb。
重新安装应用程序可能会解决此问题。
平台插件位于文件夹 ./ platforms中
(相对于可执行文件路径)。那些显然是由Qt加载的其他一些共享对象文件,其中之一是 libqxcb.so
。现在,问题是这个文件再次取决于 libQt5Gui.so
, libQt5Core.so
等。这些位于我的应用程序路径,但我怀疑 libqxcb.so
在某种程度上无法在那里找到它们,因此失败。如果我使用以下脚本来运行应用程序,它可以工作(注意: Ct
$ p $
#!/ bin / sh
DIR =$(cd$(dirname$ 0)&& pwd)
cd $ DIR
LD_LIBRARY_PATH = LD_LIBRARY_PATH :. ./Ct
但我希望在不必使用脚本运行应用程序的情况下实现此目的。
qt部署文档对此没有特别的帮助。
解决此问题的关键在于,当您查看 libqxcb.so 的ldd输出时,它将放在lib文件夹中。
libQt5Core.so.5 => < *> / plugins / platforms /./../../ lib / libQt5Core.so.5(0x00007f5f8374a000)
因此,目录结构应如下所示:
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
` - 插件
` - 平台
` - libqxcb .so
在project.pro中为lib文件夹设置你的应用程序路径:
unix:!mac {
QMAKE_LFLAGS + =-Wl,-rpath,\\ $$ ORIGIN / lib\'
}
最后,您需要设置 qt.conf 您的应用程序能够找到插件(默认情况下从平台文件夹中看):
[路径]
Prefix = ./
Libraries = lib
Plugins =插件
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.
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
这篇关于Qt,Linux,GCC:-Wl,-rpath = $ ORIGIN不适用于平台插件xcb的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!