我正在尝试建立一个可以在大多数 Linux 发行版(例如 Blender)上运行的独立二进制存档(.tar.gz)。我仍然不熟悉 CMake。据我所知,所有依赖项都可以在安装步骤使用 fixup_bundle
宏解决。而且我假设安装目录应该成为一个独立的应用程序,可以在没有安装Qt的其他计算机上复制和运行?我不确定 CPack 在这里的作用。
我试过的
我的 Qt 安装路径是 /home/<user>/Qt5.12.2/5.12.2/gcc_64/qmake
。我遵循了一些答案并将 platform/libqxcb.so
和 libQt5XcbQpa.so.5
复制到安装目录中。为了测试独立包,我将 ~/Qt5.12.2
更改为 ~/qt
。这是可执行文件运行时的错误消息:
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
并将前缀和插件路径设置为 ./
但这不起作用。我发现的一件有趣的事情是,当我设置 Plugins = /home/<user>/qt/5.12.2/gcc_64/plugins
时,会显示一个小 Qt 窗口,但会出现一堆错误消息:
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 找到了一些信息,尽管我不确定这是不是真正的原因。
ldd ~/qt/5.12.2/gcc_64/plugins/platforms/libqxcb.so
显示原来的libqxcb.so链接了Qt安装自带的库:
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 库,这不是我的项目所基于的:
./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
更新01:
这是我的 qt.conf
文件,但它不起作用。
[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
和 qml
完全从 QTDIR 复制(大约 500 MB),所以应该没有库或插件丢失。
原文由 Luis Kao 发布,翻译遵循 CC BY-SA 4.0 许可协议
我遇到了一个非常相似的问题,带有相同的错误消息。首先,通过开启调试一些
并重新运行应用程序。对我来说,这揭示了以下内容:
“无法加载库 /home/…/miniconda3/lib/python3.7/site-packages/PyQt5/Qt/plugins/platforms/libqxcb.so:(libxkbcommon-x11.so.0:无法打开共享对象文件:没有这样的文件或目录)”
“无法加载库 /home/…/miniconda3/lib/python3.7/site-packages/PyQt5/Qt/plugins/platforms/libqxcb.so:(libxkbcommon-x11.so.0:无法打开共享对象文件:没有这样的文件或目录)”
事实上,我错过了 libxkbcommon-x11.so.0 和 libxkbcommon-x11.so.0。接下来,使用 dpkg 从 linux 命令行检查您的架构。 (对我来说,命令“arch”给出了不同且无益的结果)
然后我搜索了“libxkbcommon-x11.so.0 ubuntu 18.04 amd64”,同样搜索了 libxkbcommon-x11.so.0,它会在 packages.ubuntu.com 上生成这些包。这告诉我,回想起来毫不奇怪,我缺少名为 libxkbcommon-x11-0 和 libxkbcommon-0 的软件包,并且安装这些软件包将包含所需的文件,但开发版本不会。然后解决方案: