«Failed to load platform plugin «xcb» » while launching qt5 app on linux without qt installed
I wrote application for linux which uses Qt5. But when I am trying to launch it on the linux without Qt SDK installed, the output in console is:
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. 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:
If Qt library is installed, the program works normally. If it is not installed, or the qt sdk dir is not found, the program does not work.
For those coming here from Eve Online launcher: Use eveonline.sh , not eveonline — the launcher has all libs bundled with special versions.
21 Answers 21
Use ldd (man ldd) to show shared library dependencies. Running this on 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.
Thank you! This is exactly what the problem was. libQt5DBus.so.5 should be listed in the documentation along with core and gui.
In my case sudo apt-get install libx11-xcb1 fixed the problem. But your recommendation of using ldd was what pointed me to the correct library to install. Thanks!
If you still have this problem after going through ldd , try finding the plugins/platforms directory within your Qt installation. Try to copy this entire directory to the same place as your binary or shared library file. If that works, you may set LD_LIBRARY_PATH (hacky) or, as mentioned in the answer by @bossbarber, QT_QPA_PLATFORM_PLUGIN_PATH .
In my case i didnt have the the /usr/bin/platforms dir created. Solved with: sudo ln -sf /usr/lib/x86_64-linux-gnu/qt5/plugins/platforms/ /usr/bin/
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.
The first is to export the path to the directory through the QT_QPA_PLATFORM_PLUGIN_PATH variable.
QT_QPA_PLATFORM_PLUGIN_PATH=path/to/plugins ./my_qt_app
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:
[Paths] Plugins=/path/to/plugins
More information regarding this can be found here and at using qt.conf
in my case for some reason the path inside the qt.conf (Plugins=plugins) was not recognized. I ended up supplying an empty qt.conf file, which let the global (hard coded) paths be overwritten with the qt.conf-defaults, in my case the plugins-Subfolder in the app-directory.
We were wondering why LD_LIBRARY_PATH wasn’t working, but QT_QPA_PLATFORM_PLUGIN_PATH did the trick. Super-thanks.
I tried to start my binary, compiled with Qt 5.7 , on Ubuntu 16.04 LTS where Qt 5.5 is preinstalled. It didn’t work.
At first, I inspected the binary itself with ldd as 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.
How to resolve this in Linux
Firstly you should create platforms directory where your binary is, because it is the place where Qt looks for XCB library. Copy libqxcb.so there. I wonder why authors of other answers didn’t mention this.
Then you may want to run your binary with QT_DEBUG_PLUGINS=1 environment variable set to check which dependencies of libqxcb.so are not satisfied. (You may also use ldd for this as suggested in the accepted answer).
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.5 library. 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.
P.S. thanks to the author of this answer for QT_DEBUG_PLUGINS=1 .
How to fix ‘Could not load the Qt platform plugin «xcb» in «» even though it was found.’ after fixup_bundle macro?
I’m trying to setting up a standalone binary archive (.tar.gz) that can run on most Linux distros (ex. Blender). I’m still not familiar with CMake. As far as I know, all the dependencies can be resolved at the install step with fixup_bundle macro. And I assume that the install directory should become a standalone app that can be copied and run on other computers without Qt installed? I’m not sure about the role of CPack here.
What I’ve tried
My Qt installation path is /home/
qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "" even though it was found. This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem. Available platform plugins are: xcb. [1] 25965 abort (core dumped) ./
I’ve also tried qt.conf and set the Prefix and Plugin path to ./ but that didn’t work. One interesting thing I found though is that when I set Plugins = /home/
qrc:/main.qml:4:1: module "QtQuick.Dialogs" is not installed qrc:/main.qml:1:1: module "QtQuick" is not installed qrc:/main.qml:3:1: module "QtQuick.Controls" is not installed . qrc:/main.qml:3:1: module "QtQuick.Controls" is not installed qrc:/main.qml:5:1: module "QtQuick.Controls.Styles" is not installed qrc:/main.qml:2:1: module "QtQuick.Layouts" is not installed
Then, I found some information by testing the two libqxcb.so with ldd , although I’m not sure this is the actual cause. ldd ~/qt/5.12.2/gcc_64/plugins/platforms/libqxcb.so shows that the original libqxcb.so links the libraries that come with the Qt installation:
libQt5XcbQpa.so.5 => /home/giokka/qt/5.12.2/gcc_64/plugins/platforms/../../lib/libQt5XcbQpa.so.5 (0x00007ff8936d7000) libQt5Gui.so.5 => /home/giokka/qt/5.12.2/gcc_64/plugins/platforms/../../lib/libQt5Gui.so.5 (0x00007ff892d64000) libQt5DBus.so.5 => /home/giokka/qt/5.12.2/gcc_64/plugins/platforms/../../lib/libQt5DBus.so.5 (0x00007ff892ad8000) libQt5Core.so.5 => /home/giokka/qt/5.12.2/gcc_64/plugins/platforms/../../lib/libQt5Core.so.5 (0x00007ff892343000) . libicui18n.so.56 => /home/giokka/qt/5.12.2/gcc_64/plugins/platforms/../../lib/libicui18n.so.56 (0x00007ff8914ee000) libicuuc.so.56 => /home/giokka/qt/5.12.2/gcc_64/plugins/platforms/../../lib/libicuuc.so.56 (0x00007ff891136000) libicudata.so.56 => /home/giokka/qt/5.12.2/gcc_64/plugins/platforms/../../lib/libicudata.so.56 (0x00007ff88f751000) .
ldd
./platforms/libqxcb.so: /lib64/libQt5XcbQpa.so.5: version `Qt_5_PRIVATE_API' not found (required by ./platforms/libqxcb.so) ./platforms/libqxcb.so: /lib64/libQt5Gui.so.5: version `Qt_5_PRIVATE_API' not found (required by ./platforms/libqxcb.so) libQt5XcbQpa.so.5 => /lib64/libQt5XcbQpa.so.5 (0x00007f1d8ea75000) libQt5Gui.so.5 => /lib64/libQt5Gui.so.5 (0x00007f1d8e41e000) libQt5DBus.so.5 => /lib64/libQt5DBus.so.5 (0x00007f1d8e382000) libQt5Core.so.5 => /lib64/libQt5Core.so.5 (0x00007f1d8de62000) . libicui18n.so.63 => /lib64/libicui18n.so.63 (0x00007f1d8cf37000) libicuuc.so.63 => /lib64/libicuuc.so.63 (0x00007f1d8cd64000) libicudata.so.63 => /lib64/libicudata.so.63 (0x00007f1d8afd0000) .
Source code
cmake_minimum_required(VERSION 3.10 FATAL_ERROR) project(OpenGLUnderQML LANGUAGES CXX) set(CMAKE_PREFIX_PATH "$ENV/Qt5.12.2/5.12.2/gcc_64/lib/cmake") set(qt_lib_path "$ENV/Qt5.12.2/5.12.2/gcc_64") list(APPEND qt_modules Core Gui Quick DBus ) foreach(module $) list(APPEND qt_libs "Qt5::$") endforeach() include(GNUInstallDirs) set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "$/$") set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "$/$") set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "$/$") find_package(Qt5 COMPONENTS $ REQUIRED) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(CMAKE_AUTOMOC ON) set(CMAKE_AUTORCC ON) include_directories(include/) list(APPEND headers include/Scene.hpp include/Renderer.hpp include/VertexArray.hpp include/VertexBuffer.hpp include/VertexLayout.hpp include/IndexBuffer.hpp include/Shader.hpp ) list(APPEND qrc qml/qml.qrc res/fonts.qrc res/shaders.qrc ) add_executable($ src/main.cpp src/Scene.cpp src/Renderer.cpp src/VertexArray.cpp src/VertexBuffer.cpp src/VertexLayout.cpp src/IndexBuffer.cpp src/Shader.cpp $ $ ) target_link_libraries($ PUBLIC $ ) file(RELATIVE_PATH _rel "$/install" "$") set(_rpath "\$ORIGIN/$") file(TO_NATIVE_PATH "$/install" app_RPATH) set_target_properties($ PROPERTIES SKIP_BUILD_RPATH OFF BUILD_WITH_INSTALL_RPATH OFF INSTALL_RPATH $ INSTALL_RPATH_USE_LINK_PATH ON ) install(TARGETS $ DESTINATION $/install) install( CODE " include(BundleUtilities) fixup_bundle(\"$/install/$\" \"\" \"\") " DESTINATION $/install COMPONENT Runtime ) install(FILES "$" DESTINATION $/install/platforms)
[Paths] Prefix = ./ Plugins = /home/giokka/qt/5.12.2/gcc_64/plugins
Update01:
[Paths] Prefix = . Libraries = lib Qml2Imports = qml Plugins = plugins
export LD_LIBRARY_PATH=`pwd`/lib export QML_IMPORT_PATH=`pwd`/qml export QML2_IMPORT_PATH=`pwd`/qml export QT_QPA_PLATFORM_PLUGIN_PATH=`pwd`/plugins/platforms ./OpenGLUnderQML
lib OpenGLUnderQML (the executable) plugins qml qt.conf startapp.sh (the script above)
lib , plugins , and qml are fully copied from QTDIR (about 500 MB), so there should be no library or plugin missed.