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

  • Hi

    I've build static Qt libraries (5.4.1) to minimize dependencies and simplify deploying of Qt applications on Linux. Therefore I used the settings described here:

    Then I'm using a CMake based build procedure which seems to work.
    Here is the ldd output of a simple helloworld application:

    > ldd helloworld (0x00007fff8d9fe000) => /usr/lib64/ (0x00007ff4a3a6e000) => /usr/lib64/ (0x00007ff4a3621000) => /usr/lib64/ (0x00007ff4a3296000) => /usr/lib64/ (0x00007ff4a186b000) => /lib64/ (0x00007ff4a1667000) => /lib64/ (0x00007ff4a145f000) => /lib64/ (0x00007ff4a1242000) => /usr/lib/gcc/x86_64-pc-linux-gnu/4.8.3/ (0x00007ff4a0f3e000) => /lib64/ (0x00007ff4a0c3e000) => /usr/lib/gcc/x86_64-pc-linux-gnu/4.8.3/ (0x00007ff4a0a28000) => /lib64/ (0x00007ff4a0685000)
        /lib64/ (0x00007ff4a3cc6000) => /usr/lib64/ (0x00007ff4a0352000) => /usr/lib64/ (0x00007ff4a00ab000) => /usr/lib64/ (0x00007ff49fe8c000) => /lib64/ (0x00007ff49fc76000) => /lib64/ (0x00007ff49fa66000) => /usr/lib64/ (0x00007ff49f831000)

    But when starting the application I get this error:
    This application failed to start because it could not find or load the Qt platform plugin "xcb".

    I was expecting due to the option "-qt-xcb" and static linking I would not need that plugin. Actually there is only a static library Qt/5.4.1-static/plugins/platforms/libqxcb.a

    What am I doing wrong here?

    Build process output:

    [ 66%] Building CXX object CMakeFiles/helloworld.dir/main.cpp.o
    /usr/bin/g++   -DQT_CORE_LIB -DQT_GUI_LIB -DQT_NO_DEBUG -DQT_WIDGETS_LIB -fdata-sections -ffunction-sections -Os -DNDEBUG -fPIE -I/home/gergap/work/devel/helloworld/bld -I/home/gergap/work/devel/helloworld -I/home/gergap/Qt/5.4.1-static/include -I/home/gergap/Qt/5.4.1-static/include/QtWidgets -I/home/gergap/Qt/5.4.1-static/include/QtGui -I/home/gergap/Qt/5.4.1-static/include/QtCore -I/home/gergap/Qt/5.4.1-static/mkspecs/linux-g++    -o CMakeFiles/helloworld.dir/main.cpp.o -c /home/gergap/work/devel/helloworld/main.cpp
    /usr/bin/cmake -E cmake_progress_report /home/gergap/work/devel/helloworld/bld/CMakeFiles 2
    [100%] Building CXX object CMakeFiles/helloworld.dir/helloworld_automoc.cpp.o
    /usr/bin/g++   -DQT_CORE_LIB -DQT_GUI_LIB -DQT_NO_DEBUG -DQT_WIDGETS_LIB -fdata-sections -ffunction-sections -Os -DNDEBUG -fPIE -I/home/gergap/work/devel/helloworld/bld -I/home/gergap/work/devel/helloworld -I/home/gergap/Qt/5.4.1-static/include -I/home/gergap/Qt/5.4.1-static/include/QtWidgets -I/home/gergap/Qt/5.4.1-static/include/QtGui -I/home/gergap/Qt/5.4.1-static/include/QtCore -I/home/gergap/Qt/5.4.1-static/mkspecs/linux-g++    -o CMakeFiles/helloworld.dir/helloworld_automoc.cpp.o -c /home/gergap/work/devel/helloworld/bld/helloworld_automoc.cpp
    Linking CXX executable helloworld
    /usr/bin/cmake -E cmake_link_script CMakeFiles/helloworld.dir/link.txt --verbose=1
    /usr/bin/g++    -fdata-sections -ffunction-sections -Os -DNDEBUG    -Wl,--gc-sections CMakeFiles/helloworld.dir/main.cpp.o CMakeFiles/helloworld.dir/helloworld_automoc.cpp.o  -o helloworld -rdynamic /home/gergap/Qt/5.4.1-static/lib/libQt5Widgets.a -lharfbuzz -licui18n -licuuc -licudata -ldl -lrt -lpthread /home/gergap/Qt/5.4.1-static/lib/libQt5Gui.a /home/gergap/Qt/5.4.1-static/lib/libQt5Core.a 
    make[2]: Leaving directory '/home/gergap/work/devel/helloworld/bld'
    /usr/bin/cmake -E cmake_progress_report /home/gergap/work/devel/helloworld/bld/CMakeFiles  1 2
    [100%] Built target helloworld

  • The plugin libraries are loaded by the application at run time. 'xcb' is a platform plugin for GNU/Linux. You may need others depending on your application. I don't think a static version extends to the plugins.

    Maybe you are simply missing the plugin directory under the application. You should have a folder called 'platforms' containing '' as a minimum.

  • Because I built a static Qt it contains a plugins/platforms/libqxcb.a and not an so. That's the reason why I don't understand why it fails with this error.

  • Moderators

    When compiling a static application, qmake does automatically link in Qt plugins (see e.g. Anyhow, you're using cmake, so you need to find a way to let cmake do the same ....

  • Thx for that tip. I tried qmake to get an example which I then can use to do the same with cmake. Unfortunately it also doesn' work with qmake.

    TEMPLATE = app
    CONFIG = qt static
    QT = core gui widgets
    QTPLUGIN.platforms = qxcb
    SOURCES = main.cpp
    # add missing libraries
    LIBS += -lharfbuzz -licui18n -licuuc -licudata -ldl -lrt -lpthread

    This gives me this warning when running qmake:

    Project WARNING: CONFIG-=import_qpa_plugin is deprecated. Use QTPLUGIN.platforms=- instead.

    and it does not link qxcb.

    Even when I manually link this library libqxcb.a I still get the error at runtime:

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

    Probably I need also some special compile definitions, but I don' know which.

    Is there somewhere an example how to make a simple helloworld example working with static Qt and xcb? Having a working qmake example would be enough.

    here is my helloworld main.cpp:

    #include <QApplication>
    #include <QPushButton>
    int main(int argc, char *argv[])
        QApplication app(argc, argv);
        QPushButton test("Hello World");
        return app.exec();

  • I found the issue with qmake ;-)

    CONFIG += qt static

    instead of

    CONFIG = qt static

  • Hi gergap, did you ever figure this out? I have the exact same problem :(

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.