在未安装 qt 的情况下在 linux 上启动 qt5 应用程序时“无法加载平台插件“xcb””

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17106315/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 23:13:11  来源:igfitidea点击:

"Failed to load platform plugin "xcb" " while launching qt5 app on linux without qt installed

linuxqtxcb

提问by locomotion

I wrote application for linux which uses Qt5.

我为使用 Qt5 的 linux 编写了应用程序。

But when I am trying to launch it on the linux without Qt SDK installed, the output in console is:

但是当我试图在没有安装 Qt SDK 的 linux 上启动它时,控制台中的输出是:

Failed to load platform plugin "xcb". Available platforms are:

无法加载平台插件“xcb”。可用平台有:

How can I fix this? May be I need to copy some plugin file? When I use ubuntu with Qt5 installed, but I rename Qt directory, the same problem occurs. So, it uses some file from Qt directory...

我怎样才能解决这个问题?我可能需要复制一些插件文件吗?当我在安装了 Qt5 的情况下使用 ubuntu,但我重命名 Qt 目录时,也会出现同样的问题。所以,它使用了 Qt 目录中的一些文件......

UPDATE: when I create in the app dir "platforms" folder with the file libqxcb.so, the app still doesnot start, but the error message changes:

更新:当我使用文件libqxcb.so在应用程序目录“平台”文件夹中创建时,应用程序仍然无法启动,但错误消息发生了变化:

Failed to load platform plugin "xcb". Available platforms are:

xcb

无法加载平台插件“xcb”。可用平台有:

xcb

How can this happen? How can platform plugin be available but can't be loaded?

这怎么会发生?平台插件如何可用但无法加载?

采纳答案by Abe Mishler

Use ldd (man ldd) to show shared library dependencies. Running this on libqxcb.so

使用 ldd (man ldd) 显示共享库依赖项。在 libqxcb.so 上运行它

.../platforms$ ldd libqxcb.so

shows that xcb depends on libQt5DBus.so.5 in addition to libQt5Core.so.5 and libQt5Gui.so.5 (and many other system libs). Add libQt5DBus.so.5 to your collection of shared libs and you should be ready to move on.

显示除了 libQt5Core.so.5 和 libQt5Gui.so.5(以及许多其他系统库)之外,xcb 还依赖于 libQt5DBus.so.5。将 libQt5DBus.so.5 添加到您的共享库集合中,您应该准备好继续前进了。

回答by cloose

Since version 5, Qt uses a platform abstraction system (QPA)to abstract from the underlying platform.

从版本 5 开始,Qt 使用平台抽象系统(QPA)从底层平台中抽象出来。

The implementation for each platform is provided by plugins. For X11 it is the XCB plugin. See Qt for X11 requirementsfor more information about the dependencies.

每个平台的实现由插件提供。对于 X11,它是 XCB 插件。有关依赖项的更多信息,请参阅Qt 以了解 X11 要求

回答by juzzlin

I link all Qt stuff statically to the generic Linux builds of my open source projects. It makes life a bit easier. You just need to build static versions of Qt libraries first. Of course this cannot be applied to closed source software due to licensing issues. The deployment of Qt5 apps on Linux is currently a bit problematic, because Ubuntu 12.04, for example, doesn't have Qt5 libraries in the package repositories.

我将所有 Qt 内容静态链接到我的开源项目的通用 Linux 构建。它让生活更轻松一些。您只需要首先构建 Qt 库的静态版本。当然,由于许可问题,这不能应用于闭源软件。在 Linux 上部署 Qt5 应用程序目前有点问题,因为例如 Ubuntu 12.04,包存储库中没有 Qt5 库。

回答by bossbarber

As was posted earlier, you need to make sure you install the platform plugins when you deploy your application. Depending on how you want to deploy things, there are two methods to tell your application where the platform plugins (e.g. platforms/plugins/libqxcb.so) are at runtime which may work for you.

如前所述,您需要确保在部署应用程序时安装平台插件。根据您想要如何部署事物,有两种方法可以告诉您的应用程序平台插件(例如平台/插件/libqxcb.so)在运行时的位置,这可能对您有用。

The first is to export the path to the directory through the QT_QPA_PLATFORM_PLUGIN_PATH variable.

首先是通过QT_QPA_PLATFORM_PLUGIN_PATH变量导出目录的路径。

QT_QPA_PLATFORM_PLUGIN_PATH=path/to/plugins ./my_qt_app

or

或者

export QT_QPA_PLATFORM_PLUGIN_PATH=path/to/plugins
./my_qt_app

The other option, which I prefer is to create a qt.conf file in the same directory as your executable. The contents of which would be:

我更喜欢的另一个选项是在与可执行文件相同的目录中创建一个 qt.conf 文件。其中的内容是:

[Paths]
Plugins=/path/to/plugins

More information regarding this can be found hereand at using qt.conf

可以在此处使用 qt.conf 中找到有关此的更多信息

回答by Giorgos Sfikas

In my case, I needed to deploy two Qt apps on an Ubuntu virtualbox guest. One was command-line ("app"), the other GUI_based ("app_GUI").

就我而言,我需要在 Ubuntu virtualbox 来宾上部署两个 Qt 应用程序。一个是命令行(“app”),另一个是基于 GUI(“app_GUI”)。

I used "ldd app" to find out what the required libs are, and copied them to the Ubuntu guest. While the command-line executable "app" worked ok, the GUI-based executable crashed, giving the "Failed to load platform plugin "xcb" error.I checked ldd for libxcb.so, but this too had no missing dependencies.

我使用“ldd app”找出所需的库是什么,并将它们复制到 Ubuntu 来宾。 虽然命令行可执行文件“app”工作正常,但基于 GUI 的可执行文件崩溃,出现“无法加载平台插件“xcb”错误。我检查了 libxcb.so 的 ldd,但这也没有丢失依赖项。

The problem seemed to be that while I did copy all the right libraries I accidentally had copied also libraries that were already present at the guest system.. meaning that (a) they were unnecessary to copy them in the first place and (b) worse, copying them produced incompatibilities between the install libraries. Worse still, they were undetectable by ldd like I said..

问题似乎是,虽然我确实复制了所有正确的库,但我不小心也复制了来宾系统中已经存在的库。 ,复制它们会在安装库之间产生不兼容性。更糟糕的是,就像我说的那样,它们无法被 ldd 检测到。

The solution? Make sure that you copy libraries shown as missing by ldd and absolutely no extra libraries.

解决方案?确保复制 ldd 显示为缺少的并且绝对没有额外的库

回答by Sergey P. aka azure

I faced the same problem when after installing Viber. It had all required qt libraries in /opt/viber/plugins/. I checked dependencies of /opt/viber/plugins/platforms/libqxcb.soand found missing dependencies. They were libxcb-render.so.0, libxcb-image.so.0, libxcb-icccm.so.4, libxcb-xkb.so.1So I resolved my issue by installing missing packages with this libraries:

安装 Viber 后,我遇到了同样的问题。它在/opt/viber/plugins/. 我检查了的依赖项/opt/viber/plugins/platforms/libqxcb.so并发现缺少依赖项。他们是libxcb-render.so.0, libxcb-image.so.0, libxcb-icccm.so.4,libxcb-xkb.so.1所以我通过安装缺少的包来解决我的问题:

apt-get install libxcb-xkb1 libxcb-icccm4 libxcb-image0 libxcb-render-util0

apt-get install libxcb-xkb1 libxcb-icccm4 libxcb-image0 libxcb-render-util0

回答by Neurotransmitter

I tried to start my binary, compiled with Qt 5.7, on Ubuntu 16.04 LTS where Qt 5.5 is preinstalled. Expectedly, it didn't work as is.

我尝试在预装 Qt 5.5 的 Ubuntu 16.04 LTS 上启动我的二进制文件,用 Qt 5.7 编译。不出所料,它没有按原样工作。

At first, I inspected the binary itself with lddas was suggested here, and "satisfied" all "not found" dependencies. Then this notorious This application failed to start because it could not find or load the Qt platform plugin "xcb"error was thrown.

起初,我ldd按照此处的建议检查了二进制文件本身,并“满足”了所有“未找到”的依赖项。然后This application failed to start because it could not find or load the Qt platform plugin "xcb"抛出了这个臭名昭著的错误。

How to resolve this in Linux

如何在 Linux 中解决此问题

At first, you should create platformsdirectory where your binary is, because it is the place where Qt looks for XCB library. Copy libqxcb.sothere. I wonder why authors of other answers didn't mention this.

首先,您应该创建platforms二进制文件所在的目录,因为它是 Qt 查找 XCB 库的地方。复制到libqxcb.so那里。我想知道为什么其他答案的作者没有提到这一点。

Then you may want to run your binary with QT_DEBUG_PLUGINS=1environment variable set to check which dependencies of libqxcb.soare not "satisfied". (You may also use lddfor this as suggested in the accepted answer).

然后,您可能希望在QT_DEBUG_PLUGINS=1设置了环境变量的情况下运行二进制文件,以检查哪些依赖项libqxcb.so不“满足”。(您也可以ldd按照已接受的答案中的建议使用)。

The command output may look like this:

命令输出可能如下所示:

me@xerus:/media/sf_Qt/Package$ LD_LIBRARY_PATH=. QT_DEBUG_PLUGINS=1 ./Binary
QFactoryLoader::QFactoryLoader() checking directory path "/media/sf_Qt/Package/platforms" ...
QFactoryLoader::QFactoryLoader() looking at "/media/sf_Qt/Package/platforms/libqxcb.so"
Found metadata in lib /media/sf_Qt/Package/platforms/libqxcb.so, metadata=
{
    "IID": "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.3",
    "MetaData": {
        "Keys": [
            "xcb"
        ]
    },
    "className": "QXcbIntegrationPlugin",
    "debug": false,
    "version": 329472
}


Got keys from plugin meta data ("xcb")
loaded library "/media/sf_Qt/Package/platforms/libqxcb.so"
QLibraryPrivate::loadPlugin failed on "/media/sf_Qt/Package/platforms/libqxcb.so" : "Cannot load library /media/sf_Qt/Package/platforms/libqxcb.so: (/usr/lib/x86_64-linux-gnu/libQt5DBus.so.5: version `Qt_5' not found (required by ./libQt5XcbQpa.so.5))"
This application failed to start because it could not find or load the Qt platform plugin "xcb"
in "".

Available platform plugins are: xcb.

Reinstalling the application may fix this problem.
Aborted (core dumped)

Note the failing libQt5DBus.so.5library. Copy it to your libraries path, in my case it was the same directory where my binary is (hence LD_LIBRARY_PATH=.). Repeat this process until all dependencies are satisfied.

注意失败的libQt5DBus.so.5库。将其复制到您的库路径,在我的情况下,它与我的二进制文件所在的目录相同(因此LD_LIBRARY_PATH=.)。重复此过程,直到满足所有依赖项。

P.S. thanks to the author of this answerfor QT_DEBUG_PLUGINS=1.

PS感谢笔者这个答案QT_DEBUG_PLUGINS=1

回答by Francesco

Ubuntu 16.04 64bit. I got the problem for apparently no reasons. The night before I watched a movie on my VideoLan instance, that night I would like to watch another one with VideoLan. VLC just didn't want to run because of the error into the question. I google a bit and I found the solution it solved my problem: from now on, VLC is runnable just like before. The solution is this comand:

Ubuntu 16.04 64 位。我显然没有任何原因就遇到了这个问题。我在 VideoLan 实例上看电影的前一天晚上,那天晚上我想用 VideoLan 看另一部电影。由于问题中的错误,VLC 只是不想运行。我谷歌了一下,我找到了解决我问题的解决方案:从现在开始,VLC 就像以前一样可以运行。解决方案是这个命令:

sudo ln -sf /usr/lib/x86_64-linux-gnu/qt5/plugins/platforms/ /usr/bin/

sudo ln -sf /usr/lib/x86_64-linux-gnu/qt5/plugins/platforms/ /usr/bin/

I am not able to explain what are its consequencies, but I know it creates some missing symbolic link.

我无法解释它的后果是什么,但我知道它会创建一些缺少的符号链接。

回答by jujuuj

sudo ln -sf /usr/lib/...."adapt-it"..../qt5/plugins/platforms/ /usr/bin/

sudo ln -sf /usr/lib/...."adapt-it"..../qt5/plugins/platforms/ /usr/bin/

It creates the symbolic link it's missed. Good for QT ! Good for VLC !!

它创建了它错过的符号链接。对 QT 有好处!对 VLC 有好处!!

回答by Alan

I tried the main parts of each answer, to no avail. What finally fixed it for me was to export the following environment variables:

我尝试了每个答案的主要部分,但无济于事。最终为我修复的是导出以下环境变量:

LD_LIBRARY_PATH=/usr/local/lib:~/Qt/5.9.1/gcc_64/lib
QT_QPA_PLATFORM_PLUGIN_PATH=~/Qt/5.9.1/gcc_64/plugins/