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: https://doc-snapshots.qt.io/qtifw-master/ifw-getting-started.html#setting-up-qt-installer-framework
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 linux-vdso.so.1 (0x00007fff8d9fe000) libharfbuzz.so.0 => /usr/lib64/libharfbuzz.so.0 (0x00007ff4a3a6e000) libicui18n.so.54 => /usr/lib64/libicui18n.so.54 (0x00007ff4a3621000) libicuuc.so.54 => /usr/lib64/libicuuc.so.54 (0x00007ff4a3296000) libicudata.so.54 => /usr/lib64/libicudata.so.54 (0x00007ff4a186b000) libdl.so.2 => /lib64/libdl.so.2 (0x00007ff4a1667000) librt.so.1 => /lib64/librt.so.1 (0x00007ff4a145f000) libpthread.so.0 => /lib64/libpthread.so.0 (0x00007ff4a1242000) libstdc++.so.6 => /usr/lib/gcc/x86_64-pc-linux-gnu/4.8.3/libstdc++.so.6 (0x00007ff4a0f3e000) libm.so.6 => /lib64/libm.so.6 (0x00007ff4a0c3e000) libgcc_s.so.1 => /usr/lib/gcc/x86_64-pc-linux-gnu/4.8.3/libgcc_s.so.1 (0x00007ff4a0a28000) libc.so.6 => /lib64/libc.so.6 (0x00007ff4a0685000) /lib64/ld-linux-x86-64.so.2 (0x00007ff4a3cc6000) libglib-2.0.so.0 => /usr/lib64/libglib-2.0.so.0 (0x00007ff4a0352000) libfreetype.so.6 => /usr/lib64/libfreetype.so.6 (0x00007ff4a00ab000) libgraphite2.so.3 => /usr/lib64/libgraphite2.so.3 (0x00007ff49fe8c000) libz.so.1 => /lib64/libz.so.1 (0x00007ff49fc76000) libbz2.so.1 => /lib64/libbz2.so.1 (0x00007ff49fa66000) libpng16.so.16 => /usr/lib64/libpng16.so.16 (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 'libqxcb.so' as a minimum.
-
When compiling a static application, qmake does automatically link in Qt plugins (see e.g. http://doc.qt.io/qt-5/plugins-howto.html#static-plugins). 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"); test.show(); return app.exec(); }
-
Hi gergap, did you ever figure this out? I have the exact same problem :(