国产化替代是将来各单位的主流趋势,探索自行开发应用程序在国产操作系统上正常运行是将来的主要工作之一。本文浅尝gui程序在统信社区版——deepin上遇到的小问题。
使用Qt在deepin上做了一个类似gif的帧动画弹窗,在编译运行时,程序可以正常运行,但是会报错显示:
qt.qpa.plugin: Could not find the Qt platform plugin "dxcb" in ""
在网上查,有说需要在/etc/profile中添加环境变量
export QT_QPA_PLATFORM_PLUGIN_PATH=/path/to/Qt/plugins/platforms
试了,还是报错,但程序能运行。
直接在终端运行编译后的可执行文件,又报如下错误:
/home/shell811127/workspace/qt/build-test-unknown-Debug/test: error while loading shared libraries: libicui18n.so.63: cannot open shared object file: No such file or directory
使用ldd查看程序依赖的链接库,发现有3个依赖找不到,其中包括上面报错的库名
ldd /home/shell811127/workspace/qt/build-test-unknown-Debug/test
linux-vdso.so.1 (0x00007ffe3cfa9000)libQt5Widgets.so.5 => /opt/deepin-shared-libs/Qt5.15.10gles/lib/libQt5Widgets.so.5 (0x00007f7511e00000)libQt5Gui.so.5 => /opt/deepin-shared-libs/Qt5.15.10gles/lib/libQt5Gui.so.5 (0x00007f7511600000)libQt5Core.so.5 => /opt/deepin-shared-libs/Qt5.15.10gles/lib/libQt5Core.so.5 (0x00007f7511000000)libstdc++.so.6 => /lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f7510c00000)libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f751258f000)libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f7511c1c000)libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f7512588000)libGLESv2.so.2 => /lib/x86_64-linux-gnu/libGLESv2.so.2 (0x00007f7512576000)libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f7512497000)libpng16.so.16 => /lib/x86_64-linux-gnu/libpng16.so.16 (0x00007f75115ca000)libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007f7512478000)libharfbuzz.so.0 => /lib/x86_64-linux-gnu/libharfbuzz.so.0 (0x00007f7510eda000)libicui18n.so.63 => not foundlibicuuc.so.63 => not foundlibicudata.so.63 => not foundlibdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f7512471000)libpcre2-16.so.0 => /lib/x86_64-linux-gnu/libpcre2-16.so.0 (0x00007f7510b78000)libgthread-2.0.so.0 => /lib/x86_64-linux-gnu/libgthread-2.0.so.0 (0x00007f751246a000)libglib-2.0.so.0 => /lib/x86_64-linux-gnu/libglib-2.0.so.0 (0x00007f7510a2c000)
直接使用find / -name libicui18n.so.63 查找三个缺失的文件,发现系统中存在,不过都在Qt的安装目录下:/opt/deepin-shared-libs/Qt5.15.10gles/lib/
尝试在系统目录下建立软连接:
sudo ln -s /opt/deepin-shared-libs/Qt5.15.10gles/lib/libicui18n.so.63 /usr/lib/x86_64-linux-gnu/libicui18n.so.63
再在终端执行编译后的执行文件,发现缺失的库文件名变了,说明之前的库文件系统找到了。于是尝试把刚才ldd查找的缺失库文件全部在/usr/lib/x86_64-linux-gnu/下建立软连接,程序可正常执行了。
总结,在Qt中编译运行时,程序会默认到Qt的lib目录下寻找依赖,但在操作系统中运行可执行文件,系统默认会在/usr/lib/x86_64-linux-gnu/目录下查找依赖,所以要想正常运行开发的程序,需要手动将程序依赖拷贝到系统目录下,程序方可正常运行。这有点像在windows下安装程序,需要将dll文件拷贝到system32下,只不过这里的目录是/usr/lib/x86_64-linux-gnu/。