获取静态链接Qt5的XCB插件的加载库或链接错误
Getting load library or linking error for XCB plugin of statically linked Qt5
正在尝试创建 C++ Qt5.6.1 应用程序并在 Debian 上启动它。
出现 link 错误或加载库错误。
Qt 构建为静态库,使用配置
configure -release -confirm-license -opensource -static -no-dbus -no-openssl -no-qml-debug -no-opengl -qt-freetype -qt-xcb -nomake tools -nomake tests -nomake examples -no-sql-db2 -no-sql-oci -no-sql-tds -no-sql-sqlite2 -no-sql-odbc -no-sql-ibase -no-sql-psql -skip doc -skip imageformats -skip webchannel -skip webengine -skip webview -skip sensors -skip serialport -skip script -skip multimedia
用Cmake创建的项目,库是这样指定的:
SET(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} "${QT5_LIB_ROOT}/cmake")
FIND_PACKAGE(Qt5Core REQUIRED)
FIND_PACKAGE(Qt5Gui REQUIRED)
FIND_PACKAGE(Qt5Widgets REQUIRED)
FIND_PACKAGE(Qt5Network REQUIRED)
FIND_PACKAGE( PNG REQUIRED )
FIND_PACKAGE( ZLIB REQUIRED)
FIND_PACKAGE( Threads REQUIRED )
IF(CMAKE_BUILD_TYPE STREQUAL "Debug")
SET(QT_LIBS
libqtharfbuzzng_debug.a
libqtpcre_debug.a
libQt5PlatformSupport_debug.a
libxcb-static_debug.a
)
ELSE()
SET(QT_LIBS
libqtharfbuzzng.a
libqtpcre.a
libQt5PlatformSupport.a
libxcb-static.a
)
ENDIF(CMAKE_BUILD_TYPE STREQUAL "Debug")
SET(OS_SPECIFIC_LIBS
dl
Qt5::QXcbIntegrationPlugin
${CMAKE_THREAD_LIBS_INIT}
${ZLIB_LIBRARIES}
${PNG_LIBRARY} )
FOREACH(lib_name ${QT_LIBS})
IF(NOT EXISTS ${QT5_LIB_ROOT}/${lib_name})
MESSAGE(FATAL_ERROR "Could not locate required Qt lib ${QT5_LIB_ROOT}/${lib_name}")
ENDIF()
LIST(APPEND OS_SPECIFIC_LIBS ${QT5_LIB_ROOT}/${lib_name})
ENDFOREACH(lib_name)
如果我在代码中导入 XCB 插件 (Q_IMPORT_PLUGIN(QXcbIntegrationPlugin) 它会给我 link 错误:
/Qt5/plugins/platforms/libqxcb.a(qxcbmain.o): In function `QXcbIntegrationPlugin::create(QString const&, QStringList const&, int&, char**)':
qxcbmain.cpp:(.text+0x67): undefined reference to `QXcbIntegration::QXcbIntegration(QStringList const&, int&, char**)'
Anf 如果我不导入插件 - 它不会以错误开头:
This application failed to start because it could not find or load the Qt platform plugin "xcb"
有什么帮助吗?有什么建议?
谢谢。
解决方案很简单 - 只需 link 使用适当的系统库:
通过添加
修复
FIND_PACKAGE( X11 REQUIRED )
SET(OS_SPECIFIC_LIBS
...
xcb
X11-xcb
${X11_LIBRARIES}
)
(nvm上面的评论,我发现问题了)
要添加到 Ation 答案中,我发现调试它的 "future proof" 方法是使用 qmake
作为最小样本。
testcase.pro:
QT += core gui
QTPLUGIN.platforms = qminimal qxcb
CONFIG -= import_plugins
CONFIG += static
SOURCES += main.cpp
main.cpp:
#include <QCoreApplication>
#include <QDebug>
#include <QtPlugin>
Q_IMPORT_PLUGIN(QXcbIntegrationPlugin)
int main(int argc, char **argv)
{
QCoreApplication app(argc, argv);
qDebug() << "Does something!";
return app.exec();
}
一旦存在,运行 qmake
和 make
。 make
输出将包含您需要放入 CMake 项目 CMAKE_CXX_LINK_EXECUTABLE
变量中的所有 -l****
。我可以自动化。
解决方案并不简单。如果你在这里,也许你做错了什么。但是你需要 link res/archdatadir/plugins/platforms/libqxcb.a
和 lib/libQt{$Qt_MAJOR_VERSION}XcbQpa.a
cmake 的肮脏示例在这里 https://github.com/Jihadist/StaticQtPlugin/blob/master/CMakeLists.txt#L56 并且不要忘记 Q_IMPORT_PLUGIN(QXcbIntegrationPlugin)
感谢https://whosebug.com/users/1672598/emmanuel-lepage-vallee
正在尝试创建 C++ Qt5.6.1 应用程序并在 Debian 上启动它。 出现 link 错误或加载库错误。
Qt 构建为静态库,使用配置
configure -release -confirm-license -opensource -static -no-dbus -no-openssl -no-qml-debug -no-opengl -qt-freetype -qt-xcb -nomake tools -nomake tests -nomake examples -no-sql-db2 -no-sql-oci -no-sql-tds -no-sql-sqlite2 -no-sql-odbc -no-sql-ibase -no-sql-psql -skip doc -skip imageformats -skip webchannel -skip webengine -skip webview -skip sensors -skip serialport -skip script -skip multimedia
用Cmake创建的项目,库是这样指定的:
SET(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} "${QT5_LIB_ROOT}/cmake")
FIND_PACKAGE(Qt5Core REQUIRED)
FIND_PACKAGE(Qt5Gui REQUIRED)
FIND_PACKAGE(Qt5Widgets REQUIRED)
FIND_PACKAGE(Qt5Network REQUIRED)
FIND_PACKAGE( PNG REQUIRED )
FIND_PACKAGE( ZLIB REQUIRED)
FIND_PACKAGE( Threads REQUIRED )
IF(CMAKE_BUILD_TYPE STREQUAL "Debug")
SET(QT_LIBS
libqtharfbuzzng_debug.a
libqtpcre_debug.a
libQt5PlatformSupport_debug.a
libxcb-static_debug.a
)
ELSE()
SET(QT_LIBS
libqtharfbuzzng.a
libqtpcre.a
libQt5PlatformSupport.a
libxcb-static.a
)
ENDIF(CMAKE_BUILD_TYPE STREQUAL "Debug")
SET(OS_SPECIFIC_LIBS
dl
Qt5::QXcbIntegrationPlugin
${CMAKE_THREAD_LIBS_INIT}
${ZLIB_LIBRARIES}
${PNG_LIBRARY} )
FOREACH(lib_name ${QT_LIBS})
IF(NOT EXISTS ${QT5_LIB_ROOT}/${lib_name})
MESSAGE(FATAL_ERROR "Could not locate required Qt lib ${QT5_LIB_ROOT}/${lib_name}")
ENDIF()
LIST(APPEND OS_SPECIFIC_LIBS ${QT5_LIB_ROOT}/${lib_name})
ENDFOREACH(lib_name)
如果我在代码中导入 XCB 插件 (Q_IMPORT_PLUGIN(QXcbIntegrationPlugin) 它会给我 link 错误:
/Qt5/plugins/platforms/libqxcb.a(qxcbmain.o): In function `QXcbIntegrationPlugin::create(QString const&, QStringList const&, int&, char**)':
qxcbmain.cpp:(.text+0x67): undefined reference to `QXcbIntegration::QXcbIntegration(QStringList const&, int&, char**)'
Anf 如果我不导入插件 - 它不会以错误开头:
This application failed to start because it could not find or load the Qt platform plugin "xcb"
有什么帮助吗?有什么建议?
谢谢。
解决方案很简单 - 只需 link 使用适当的系统库: 通过添加
修复FIND_PACKAGE( X11 REQUIRED )
SET(OS_SPECIFIC_LIBS
...
xcb
X11-xcb
${X11_LIBRARIES}
)
(nvm上面的评论,我发现问题了)
要添加到 Ation 答案中,我发现调试它的 "future proof" 方法是使用 qmake
作为最小样本。
testcase.pro:
QT += core gui
QTPLUGIN.platforms = qminimal qxcb
CONFIG -= import_plugins
CONFIG += static
SOURCES += main.cpp
main.cpp:
#include <QCoreApplication>
#include <QDebug>
#include <QtPlugin>
Q_IMPORT_PLUGIN(QXcbIntegrationPlugin)
int main(int argc, char **argv)
{
QCoreApplication app(argc, argv);
qDebug() << "Does something!";
return app.exec();
}
一旦存在,运行 qmake
和 make
。 make
输出将包含您需要放入 CMake 项目 CMAKE_CXX_LINK_EXECUTABLE
变量中的所有 -l****
。我可以自动化。
解决方案并不简单。如果你在这里,也许你做错了什么。但是你需要 link res/archdatadir/plugins/platforms/libqxcb.a
和 lib/libQt{$Qt_MAJOR_VERSION}XcbQpa.a
cmake 的肮脏示例在这里 https://github.com/Jihadist/StaticQtPlugin/blob/master/CMakeLists.txt#L56 并且不要忘记 Q_IMPORT_PLUGIN(QXcbIntegrationPlugin)
感谢https://whosebug.com/users/1672598/emmanuel-lepage-vallee