本文最后更新于:2024年5月7日 下午
在使用 VS code 调试Linux远程代码时报错,could not find or load the Qt platform plugin "xcb"
,本文记录解决方案。
错误复现
1 2 3 This application failed to start because it could not find or load the Qt platform plugin "xcb" . Available platform plugins are: linuxfb, minimal, offscreen, xcb. Reinstalling the application may fix this problem.
错误分析
部署软件时,没有将Qt插件文件下的platforms中的libqxcb.so库部署上去
或者部署了部分Qt库,但是该库依赖的其他库丢失
总之就是Qt依赖的或间接依赖的库在系统路径下找不到了
调试方法
1 export QT_DEBUG_PLUGINS =1
解决方案
查找到出问题的库
如果出问题的库不在,那就补足到系统LD_LIBRARY_PATH
路径
如果库存在,找到那个库,运行命令:
可以看到该库的依赖库出问题在哪里,继续迭代地解决依赖问题
解决问题(示例)
由于库特别多,可能我们出问题的库不尽相同,但是思路是类似的,我以我面临的问题为例记录解决方案
1 2 3 4 Got keys from plugin meta data ("xcb" ) QFactoryLoader::QFactoryLoader() checking directory path "/root/anaconda3/bin/platforms" ... Cannot load library /root/anaconda3/plugins/platforms/libqxcb.so: (libXi.so.6 : cannot open shared object file : No such file or directory ) QLibraryPrivate::loadPlugin failed on "/root/anaconda3/plugins/platforms/libqxcb.so" : "Cannot load library /root/anaconda3/plugins/platforms/libqxcb.so: (libXi.so.6: cannot open shared object file: No such file or directory)"
可以看到是 /root/anaconda3/plugins/platforms/libqxcb.so
依赖的 libXi.so.6
有问题
我们来到libqxcb.so
面前,查看他依赖库的情况:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 :~/anaconda3/ plugins/platforms linux-vdso.so.1 (0 x00007ffcbc9aa000) libQt5XcbQpa.so.5 => /root/ anaconda3/plugins/ platforms/./ ../../ lib/libQt5XcbQpa.so.5 (0 x00007fe8eac1c000) libQt5DBus.so.5 => /root/ anaconda3/plugins/ platforms/./ ../../ lib/libQt5DBus.so.5 (0 x00007fe8eabbc000) libgthread-2.0 .so.0 => /root/ anaconda3/plugins/ platforms/./ ../../ lib/libgthread-2.0 .so.0 (0 x00007fe8eabb7000) librt.so.1 => /lib/ x86_64-linux-gnu/librt.so.1 (0 x00007fe8eaba5000) libglib-2.0 .so.0 => /root/ anaconda3/plugins/ platforms/./ ../../ lib/libglib-2.0 .so.0 (0 x00007fe8eaa70000) libfontconfig.so.1 => /root/ anaconda3/plugins/ platforms/./ ../../ lib/libfontconfig.so.1 (0 x00007fe8eaa28000) libfreetype.so.6 => /root/ anaconda3/plugins/ platforms/./ ../../ lib/libfreetype.so.6 (0 x00007fe8ea973000) libQt5Gui.so.5 => /root/ anaconda3/plugins/ platforms/./ ../../ lib/libQt5Gui.so.5 (0 x00007fe8ea5a7000) libQt5Core.so.5 => /root/ anaconda3/plugins/ platforms/./ ../../ lib/libQt5Core.so.5 (0 x00007fe8ea190000) libGL.so.1 => /lib/ x86_64-linux-gnu/libGL.so.1 (0 x00007fe8ea108000) libpthread.so.0 => /lib/ x86_64-linux-gnu/libpthread.so.0 (0 x00007fe8ea0e5000) libX11-xcb.so.1 => /lib/ x86_64-linux-gnu/libX11-xcb.so.1 (0 x00007fe8ea0de000) libX11.so.6 => /lib/ x86_64-linux-gnu/libX11.so.6 (0 x00007fe8e9fa1000) libXi.so.6 => not found libxcb.so.1 => /root/ anaconda3/plugins/ platforms/./ ../../ lib/libxcb.so.1 (0 x00007fe8e9f75000) libdl.so.2 => /lib/ x86_64-linux-gnu/libdl.so.2 (0 x00007fe8e9f6f000) libstdc++.so.6 => /root/ anaconda3/plugins/ platforms/./ ../../ lib/libstdc++.so.6 (0 x00007fe8e9dfb000) libm.so.6 => /lib/ x86_64-linux-gnu/libm.so.6 (0 x00007fe8e9caa000) libgcc_s.so.1 => /root/ anaconda3/plugins/ platforms/./ ../../ lib/libgcc_s.so.1 (0 x00007fe8e9c96000) libc.so.6 => /lib/ x86_64-linux-gnu/libc.so.6 (0 x00007fe8e9aa4000) libXi.so.6 => not found libdbus-1 .so.3 => /root/ anaconda3/plugins/ platforms/./ ../../ lib/./ libdbus-1 .so.3 (0 x00007fe8e9a4f000) libpcre.so.1 => /root/ anaconda3/plugins/ platforms/./ ../../ lib/./ libpcre.so.1 (0 x00007fe8e9a06000) libxml2.so.2 => /root/ anaconda3/plugins/ platforms/./ ../../ lib/./ libxml2.so.2 (0 x00007fe8e989f000) libuuid.so.1 => /root/ anaconda3/plugins/ platforms/./ ../../ lib/./ libuuid.so.1 (0 x00007fe8e969b000) libz.so.1 => /root/ anaconda3/plugins/ platforms/./ ../../ lib/./ libz.so.1 (0 x00007fe8e967b000) libpng16.so.16 => /root/ anaconda3/plugins/ platforms/./ ../../ lib/./ libpng16.so.16 (0 x00007fe8e9642000) libicui18n.so.58 => /root/ anaconda3/plugins/ platforms/./ ../../ lib/./ libicui18n.so.58 (0 x00007fe8e93c1000) libicuuc.so.58 => /root/ anaconda3/plugins/ platforms/./ ../../ lib/./ libicuuc.so.58 (0 x00007fe8e920e000) libicudata.so.58 => /root/ anaconda3/plugins/ platforms/./ ../../ lib/./ libicudata.so.58 (0 x00007fe8e790c000) /lib64/ ld-linux-x86-64 .so.2 (0 x00007fe8ead12000) libGLdispatch.so.0 => /lib/ x86_64-linux-gnu/libGLdispatch.so.0 (0 x00007fe8e7854000) libGLX.so.0 => /lib/ x86_64-linux-gnu/libGLX.so.0 (0 x00007fe8e7820000) libXau.so.6 => /lib/ x86_64-linux-gnu/libXau.so.6 (0 x00007fe8e7818000) liblzma.so.5 => /root/ anaconda3/plugins/ platforms/./ ../../ lib/./ ./liblzma.so.5 (0 x00007fe8e77ef000)
可以看到 libXi.so.6
没有找到,他本质上指向 libXi.so.6.1.0
于是我从其他电脑上复制来了 libXi.so.6.1.0
放在了 /usr/lib/x86_64-linux-gnu/
中,并建立软连接 libXi.so.6
1 2 3 :/usr/lib/x86_64-linux-gnu lrwxrwxrwx 1 root root 14 Nov 11 17 : 29 libXi.so.6 -> libXi.so.6.1 .0 -rw-r--r-- 1 1002 1002 63944 Nov 11 17 : 27 libXi.so.6.1 .0
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 :~/anaconda3/ plugins/platforms linux-vdso.so.1 (0 x00007ffdf59b6000) libQt5XcbQpa.so.5 => /root/ anaconda3/plugins/ platforms/./ ../../ lib/libQt5XcbQpa.so.5 (0 x00007f1aeabc7000) libQt5DBus.so.5 => /root/ anaconda3/plugins/ platforms/./ ../../ lib/libQt5DBus.so.5 (0 x00007f1aeab67000) libgthread-2.0 .so.0 => /root/ anaconda3/plugins/ platforms/./ ../../ lib/libgthread-2.0 .so.0 (0 x00007f1aeab62000) librt.so.1 => /lib/ x86_64-linux-gnu/librt.so.1 (0 x00007f1aeab50000) libglib-2.0 .so.0 => /root/ anaconda3/plugins/ platforms/./ ../../ lib/libglib-2.0 .so.0 (0 x00007f1aeaa1b000) libfontconfig.so.1 => /root/ anaconda3/plugins/ platforms/./ ../../ lib/libfontconfig.so.1 (0 x00007f1aea9d3000) libfreetype.so.6 => /root/ anaconda3/plugins/ platforms/./ ../../ lib/libfreetype.so.6 (0 x00007f1aea91e000) libQt5Gui.so.5 => /root/ anaconda3/plugins/ platforms/./ ../../ lib/libQt5Gui.so.5 (0 x00007f1aea552000) libQt5Core.so.5 => /root/ anaconda3/plugins/ platforms/./ ../../ lib/libQt5Core.so.5 (0 x00007f1aea13b000) libGL.so.1 => /lib/ x86_64-linux-gnu/libGL.so.1 (0 x00007f1aea0b3000) libpthread.so.0 => /lib/ x86_64-linux-gnu/libpthread.so.0 (0 x00007f1aea090000) libX11-xcb.so.1 => /lib/ x86_64-linux-gnu/libX11-xcb.so.1 (0 x00007f1aea089000) libX11.so.6 => /lib/ x86_64-linux-gnu/libX11.so.6 (0 x00007f1ae9f4c000) libXi.so.6 => /lib/ x86_64-linux-gnu/libXi.so.6 (0 x00007f1ae9d3c000) libxcb.so.1 => /root/ anaconda3/plugins/ platforms/./ ../../ lib/libxcb.so.1 (0 x00007f1ae9d10000) libdl.so.2 => /lib/ x86_64-linux-gnu/libdl.so.2 (0 x00007f1ae9d0a000) libstdc++.so.6 => /root/ anaconda3/plugins/ platforms/./ ../../ lib/libstdc++.so.6 (0 x00007f1ae9b96000) libm.so.6 => /lib/ x86_64-linux-gnu/libm.so.6 (0 x00007f1ae9a45000) libgcc_s.so.1 => /root/ anaconda3/plugins/ platforms/./ ../../ lib/libgcc_s.so.1 (0 x00007f1ae9a31000) libc.so.6 => /lib/ x86_64-linux-gnu/libc.so.6 (0 x00007f1ae983f000) libdbus-1 .so.3 => /root/ anaconda3/plugins/ platforms/./ ../../ lib/./ libdbus-1 .so.3 (0 x00007f1ae97ea000) libpcre.so.1 => /root/ anaconda3/plugins/ platforms/./ ../../ lib/./ libpcre.so.1 (0 x00007f1ae97a3000) libxml2.so.2 => /root/ anaconda3/plugins/ platforms/./ ../../ lib/./ libxml2.so.2 (0 x00007f1ae963a000) libuuid.so.1 => /root/ anaconda3/plugins/ platforms/./ ../../ lib/./ libuuid.so.1 (0 x00007f1ae9436000) libz.so.1 => /root/ anaconda3/plugins/ platforms/./ ../../ lib/./ libz.so.1 (0 x00007f1ae9416000) libpng16.so.16 => /root/ anaconda3/plugins/ platforms/./ ../../ lib/./ libpng16.so.16 (0 x00007f1ae93dd000) libicui18n.so.58 => /root/ anaconda3/plugins/ platforms/./ ../../ lib/./ libicui18n.so.58 (0 x00007f1ae915e000) libicuuc.so.58 => /root/ anaconda3/plugins/ platforms/./ ../../ lib/./ libicuuc.so.58 (0 x00007f1ae8fa9000) libicudata.so.58 => /root/ anaconda3/plugins/ platforms/./ ../../ lib/./ libicudata.so.58 (0 x00007f1ae76a7000) /lib64/ ld-linux-x86-64 .so.2 (0 x00007f1aeacbd000) libGLdispatch.so.0 => /lib/ x86_64-linux-gnu/libGLdispatch.so.0 (0 x00007f1ae75ef000) libGLX.so.0 => /lib/ x86_64-linux-gnu/libGLX.so.0 (0 x00007f1ae75bb000) libXext.so.6 => /lib/ x86_64-linux-gnu/libXext.so.6 (0 x00007f1ae75a6000) libXau.so.6 => /lib/ x86_64-linux-gnu/libXau.so.6 (0 x00007f1ae759e000) liblzma.so.5 => /root/ anaconda3/plugins/ platforms/./ ../../ lib/./ ./liblzma.so.5 (0 x00007f1ae7575000)
发现缺少的 libXi.so.6
不再是 not found
的状态了
运行程序,这部分已经不再报错了
参考资料
文章链接:
https://www.zywvvd.com/notes/system/linux/remote-linux-gui/qt-plat-xcb-err/qt-plat-xcb-err/