Linux 获取静态链接Qt5的XCB插件的加载库或链接错误 试图创建C++ Qt5.61应用程序并在Debian上启动它。 获取链接错误或加载库错误
Qt构建到静态libs,用于配置Linux 获取静态链接Qt5的XCB插件的加载库或链接错误 试图创建C++ Qt5.61应用程序并在Debian上启动它。 获取链接错误或加载库错误,linux,qt,debian,qt5,xcb,Linux,Qt,Debian,Qt5,Xcb,Qt构建到静态libs,用于配置 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
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创建的项目,LIB的指定方式如下:
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)),它会给出链接错误:
/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"
有什么帮助吗?建议
谢谢。解决方案很简单-只需与适当的系统库链接即可: 加上
FIND_PACKAGE( X11 REQUIRED )
SET(OS_SPECIFIC_LIBS
...
xcb
X11-xcb
${X11_LIBRARIES}
)
(在上面的评论中,我发现了问题)
为了补充这个问题的答案,我发现调试这个问题的“未来证明”方法是使用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();
}
#包括
#包括
#包括
Q_导入插件(QXcbIntegrationPlugin)
int main(int argc,字符**argv)
{
QCore应用程序应用程序(argc、argv);
qDebug()我认为静态链接和CMake现在已经崩溃了,cf.,但这看起来是另一个问题——我认为你不应该在平台插件中手动链接,CMake/Qt集成应该会解决这个问题,但我可能错了……这有点不同。我遇到的问题是针对linux的。没有问题吗OSX和Windows(不同的插件,所以,特定于平台)。如果我错过了一些明显的东西,很抱歉,但是nm-gC libqxcb.a
showQXcbIntegration::QXcbIntegration
未定义。我看不出答案是如何解决的。这对我不起作用(我有完全相同的问题).你的CMakeLists.txt
是开源的,我可以看一下吗?