获取静态链接Qt5的XCB插件的加载库或链接错误

时间:2016-07-22 16:49:12

标签: linux qt debian qt5 xcb

尝试创建C ++ Qt5.6.1应用程序并在Debian上启动它。 获取链接错误或加载库错误。

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创建的项目,libs以这种方式指定:

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**)'

如果我不导入插件,那么它就不会以错误开头:

This application failed to start because it could not find or load the Qt platform plugin "xcb"

有任何帮助吗?建议?

感谢。

3 个答案:

答案 0 :(得分:1)

解决方案很简单 - 只需链接到适当的系统库: 已添加

修复
FIND_PACKAGE( X11 REQUIRED )

SET(OS_SPECIFIC_LIBS
   ...
   xcb
   X11-xcb
   ${X11_LIBRARIES}
)

答案 1 :(得分:1)

(上面的评论,我发现了问题)

要添加到Ation答案,我发现调试此问题的“面向未来”的方法是使用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();
}

一旦存在,请运行qmakemakemake输出将包含您需要放入CMake项目-l****变量的所有CMAKE_CXX_LINK_EXECUTABLE。我可以自动化。

答案 2 :(得分:0)

解决方案并不简单。如果你在这里,也许你做错了什么。但是您需要链接 res/archdatadir/plugins/platforms/libqxcb.alib/libQt{$Qt_MAJOR_VERSION}XcbQpa.a cmake 的脏例子在这里 https://github.com/Jihadist/StaticQtPlugin/blob/master/CMakeLists.txt#L56 并且不要忘记 Q_IMPORT_PLUGIN(QXcbIntegrationPlugin) 感谢https://stackoverflow.com/users/1672598/emmanuel-lepage-vallee