如何修复“无法加载Qt平台插件“ xcb”,在“”中即使找到了。”在fixup_bundle宏之后? [英] How to fix 'Could not load the Qt platform plugin "xcb" in "" even though it was found.' after fixup_bundle macro?

查看:1190
本文介绍了如何修复“无法加载Qt平台插件“ xcb”,在“”中即使找到了。”在fixup_bundle宏之后?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试设置一个可以在大多数Linux发行版(例如Blender)上运行的独立二进制存档(.tar.gz)。我仍然不熟悉CMake。据我所知,所有依赖项都可以在安装步骤使用 fixup_bundle 宏来解决。而且我认为安装目录应该成为一个独立的应用程序,可以在未安装Qt的情况下复制并在其他计算机上运行?我不确定CPack在这里的作用。

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.

我的Qt安装路径为 /home/<user>/Qt5.12.2/5.12.2/gcc_64/qmake 。我遵循了一些答案,并将 platform / libqxcb.so libQt5XcbQpa.so.5 复制到安装目录中。为了测试独立程序包,我将〜/ Qt5.12.2 更改为〜/ qt 。这是可执行文件运行时的错误消息:

My Qt installation path is /home/<user>/Qt5.12.2/5.12.2/gcc_64/qmake. I've followed some answers and have copied platform/libqxcb.so and libQt5XcbQpa.so.5 into the install directory. In order to test the standalone package, I change ~/Qt5.12.2 into ~/qt. And this is the error message when the executable run:

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)  ./<executable_name>

我也尝试过 qt.conf 并将Prefix和Plugin路径设置为 ./ ,但这无效。我发现的一件有趣的事是,当我设置 Plugins = /home/<user>/qt/5.12.2/gcc_64/plugins 时,会显示一个小的Qt窗口,但带有一堆错误消息:

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/<user>/qt/5.12.2/gcc_64/plugins, a little Qt window shows, but comes with a bunch of error messages:

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

然后,我通过使用 ldd 测试两个libqxcb.so找到了一些信息,尽管我不确定这是

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 显示原始的libqxcb.so链接了Qt安装随附的库:

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< path_to_project> /build/install/platforms/libqxcb.so 显示它链接到系统Qt库,这不是我的项目所基于的库:

ldd <path_to_project>/build/install/platforms/libqxcb.so shows it links to the system Qt library, which is not the one my project built against on:

./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)
......



源代码



CMakeLists.txt

cmake_minimum_required(VERSION 3.10 FATAL_ERROR)

project(OpenGLUnderQML LANGUAGES CXX)

set(CMAKE_PREFIX_PATH "$ENV{HOME}/Qt5.12.2/5.12.2/gcc_64/lib/cmake")
set(qt_lib_path "$ENV{HOME}/Qt5.12.2/5.12.2/gcc_64")

list(APPEND qt_modules
    Core
    Gui
    Quick
    DBus
)

foreach(module ${qt_modules})
    list(APPEND qt_libs "Qt5::${module}")
endforeach()

include(GNUInstallDirs)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}")
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_BINDIR}")


find_package(Qt5 COMPONENTS ${qt_modules} 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(${PROJECT_NAME}
    src/main.cpp
    src/Scene.cpp
    src/Renderer.cpp
    src/VertexArray.cpp
    src/VertexBuffer.cpp
    src/VertexLayout.cpp
    src/IndexBuffer.cpp
    src/Shader.cpp
    ${headers}
    ${qrc}
)

target_link_libraries(${PROJECT_NAME}
    PUBLIC
        ${qt_libs}
)


file(RELATIVE_PATH _rel "${CMAKE_INSTALL_PREFIX}/install" "${CMAKE_INSTALL_PREFIX}")
set(_rpath "\$ORIGIN/${_rel}")
file(TO_NATIVE_PATH "${_rpath}/install" app_RPATH)

set_target_properties(${PROJECT_NAME}
    PROPERTIES
        SKIP_BUILD_RPATH OFF
        BUILD_WITH_INSTALL_RPATH OFF
        INSTALL_RPATH ${app_RPATH}
        INSTALL_RPATH_USE_LINK_PATH ON
)

install(TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_BINARY_DIR}/install)
install(
    CODE "
include(BundleUtilities)
fixup_bundle(\"${CMAKE_BINARY_DIR}/install/${PROJECT_NAME}\" \"\" \"\")
"
    DESTINATION ${CMAKE_BINARY_DIR}/install
    COMPONENT Runtime
)

install(FILES "$<TARGET_FILE:Qt5::QXcbIntegrationPlugin>" DESTINATION ${CMAKE_BINARY_DIR}/install/platforms)

qt.conf

[Paths]
Prefix = ./
Plugins = /home/giokka/qt/5.12.2/gcc_64/plugins



Update01:



这是我的 qt.conf 文件,但是它不起作用。

Update01:

This is my qt.conf file, but it doesn't work.

[Paths]
Prefix = .
Libraries = lib
Qml2Imports = qml
Plugins = plugins

但是,此脚本在我的编译计算机上有效,而在另一台计算机上无效:

However, this script works on my compiling computer but not on the other computer:

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 插件 qml 是从QTDIR完全复制的(大约500 MB),因此不应丢失任何库或插件。

lib, plugins, and qml are fully copied from QTDIR (about 500 MB), so there should be no library or plugin missed.

推荐答案

我遇到了一个非常类似的问题,并带有相同的错误消息。
首先,通过打开

I ran into a very similar problem with the same error message. First, debug some by turning on


export QT_DEBUG_PLUGIN = 1

export QT_DEBUG_PLUGIN=1

然后重新运行该应用程序。对我来说,这揭示了以下内容:

and rerun the application. For me this revealed the following:

无法加载库/home/.../miniconda3/lib/python3.7/site-packages/PyQt5/Qt/plugins/platforms/ libqxcb.so:
(libxkbcommon-x11.so.0:无法打开共享对象文件:没有这样的文件或目录)

"Cannot load library /home/.../miniconda3/lib/python3.7/site-packages/PyQt5/Qt/plugins/platforms/libqxcb.so: (libxkbcommon-x11.so.0: cannot open shared object file: No such file or directory)"

无法加载库/ home / ... / miniconda3 / lib / python3.7 / site-packages / PyQt5 / Qt / plugins / platforms / libqxcb.so:
(libxkbcommon-x11.so.0:
无法打开共享对象文件:没有这样的文件或目录)

"Cannot load library /home/.../miniconda3/lib/python3.7/site-packages/PyQt5/Qt/plugins/platforms/libqxcb.so: (libxkbcommon-x11.so.0: cannot open shared object file: No such file or directory)"

确实,我缺少libxkbcommon-x11.so.0和libxkbcommon-x11.so.0。接下来,从linux命令行使用dpkg检查您的体系结构。 (对我来说,命令 arch给出了不同且无益的结果)

Indeed, I was missing libxkbcommon-x11.so.0 and libxkbcommon-x11.so.0. Next, check your architecture using dpkg from the linux command line. (For me, the command "arch" gave a different and unhelpful result)


dpkg --print-architecture #result for me:amd64

dpkg --print-architecture #result for me: amd64

然后,我用Google搜索 libxkbcommon-x11.so.0 ubuntu 18.04 amd64,同样用Google搜索 libxkbcommon-x11.so.0,这会在软件包中生成这些软件包.ubuntu.com。毫无疑问,这告诉了我,我缺少名为libxkbcommon-x11-0和libxkbcommon-0的软件包,并且安装这些软件包将包含所需的文件,但开发版本不会。然后是解决方案:

I then googled "libxkbcommon-x11.so.0 ubuntu 18.04 amd64", and likewise for libxkbcommon-x11.so.0, which yields those packages on packages.ubuntu.com. That told me, in retrospect unsurprisingly, I'm missing packages called libxkbcommon-x11-0 and libxkbcommon-0, and that installing those packages will include the needed files, but the dev versions will not. Then the solution:


sudo apt-get update

sudo apt-get update

sudo apt-get install libxkbcommon0

sudo apt-get install libxkbcommon0

sudo apt-get install libxkbcommon-x11-0

sudo apt-get install libxkbcommon-x11-0

这篇关于如何修复“无法加载Qt平台插件“ xcb”,在“”中即使找到了。”在fixup_bundle宏之后?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆