Tuesday, April 12, 2022

[SOLVED] Getting load library or linking error for XCB plugin of statically linked Qt5

Issue

Trying to create C++ Qt5.6.1 application and start it on Debian. Getting either link error or load library error.

Qt build to a static libs, used configuration

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

Project created with Cmake, libs are specified in this way:

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)

And if I'm importing XCB plugin in the code ( Q_IMPORT_PLUGIN(QXcbIntegrationPlugin) it gives me link error:

    /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 if I don't import plugin - it just not start with error:

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

Any help? advice?

Thanks.


Solution

Solution was simple - just link with proper system libs: fixed with adding

FIND_PACKAGE( X11 REQUIRED )

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


Answered By - Ation
Answer Checked By - Marilyn (WPSolving Volunteer)