Qt应用程序中与Qt版本相关的运行时错误

时间:2018-06-15 22:05:09

标签: c++ linux qt dependencies qt-creator

我正在使用Qt Creator在Linux KDE neon上开发和运行应用程序。

我的应用程序突然拒绝打开一些URL,这是一个以前正常工作的功能。我没有改变任何东西,所以我猜一些KDE霓虹灯更新打破了它。

调用该函数时,我得到了这个调试输出:

kde-open5: /home/<user>/Qt/5.10.0/gcc_64/lib/libQt5Core.so.5: version `Qt_5.11' not found (required by /usr/lib/x86_64-linux-gnu/libKF5KIOWidgets.so.5)
kde-open5: /home/<user>/Qt/5.10.0/gcc_64/lib/libQt5Core.so.5: version `Qt_5.11' not found (required by /usr/lib/x86_64-linux-gnu/libKF5KIOCore.so.5)
kde-open5: /home/<user>/Qt/5.10.0/gcc_64/lib/libQt5Core.so.5: version `Qt_5.11' not found (required by /usr/lib/x86_64-linux-gnu/libKF5I18n.so.5)
kde-open5: /home/<user>/Qt/5.10.0/gcc_64/lib/libQt5Core.so.5: version `Qt_5.11' not found (required by /usr/lib/x86_64-linux-gnu/libKF5CoreAddons.so.5)
kde-open5: /home/<user>/Qt/5.10.0/gcc_64/lib/libQt5Core.so.5: version `Qt_5.11' not found (required by /usr/lib/x86_64-linux-gnu/libKF5JobWidgets.so.5)
kde-open5: /home/<user>/Qt/5.10.0/gcc_64/lib/libQt5Core.so.5: version `Qt_5.11' not found (required by /usr/lib/x86_64-linux-gnu/libKF5Service.so.5)
kde-open5: /home/<user>/Qt/5.10.0/gcc_64/lib/libQt5Core.so.5: version `Qt_5.11' not found (required by /usr/lib/x86_64-linux-gnu/libKF5Completion.so.5)
kde-open5: /home/<user>/Qt/5.10.0/gcc_64/lib/libQt5Core.so.5: version `Qt_5.11' not found (required by /usr/lib/x86_64-linux-gnu/libKF5IconThemes.so.5)
kde-open5: /home/<user>/Qt/5.10.0/gcc_64/lib/libQt5Core.so.5: version `Qt_5.11' not found (required by /usr/lib/x86_64-linux-gnu/libKF5WindowSystem.so.5)
kde-open5: /home/<user>/Qt/5.10.0/gcc_64/lib/libQt5Core.so.5: version `Qt_5.11' not found (required by /usr/lib/x86_64-linux-gnu/libKF5ConfigWidgets.so.5)
kde-open5: /home/<user>/Qt/5.10.0/gcc_64/lib/libQt5Core.so.5: version `Qt_5.11' not found (required by /usr/lib/x86_64-linux-gnu/libKF5WidgetsAddons.so.5)
kde-open5: /home/<user>/Qt/5.10.0/gcc_64/lib/libQt5Core.so.5: version `Qt_5.11' not found (required by /usr/lib/x86_64-linux-gnu/libKF5ConfigGui.so.5)
kde-open5: /home/<user>/Qt/5.10.0/gcc_64/lib/libQt5Core.so.5: version `Qt_5.11' not found (required by /usr/lib/x86_64-linux-gnu/libKF5ConfigCore.so.5)
kde-open5: /home/<user>/Qt/5.10.0/gcc_64/lib/libQt5Core.so.5: version `Qt_5.11' not found (required by /usr/lib/x86_64-linux-gnu/libKF5DBusAddons.so.5)
kde-open5: /home/<user>/Qt/5.10.0/gcc_64/lib/libQt5Core.so.5: version `Qt_5.11' not found (required by /usr/lib/x86_64-linux-gnu/libKF5Auth.so.5)
kde-open5: /home/<user>/Qt/5.10.0/gcc_64/lib/libQt5Core.so.5: version `Qt_5.11' not found (required by /usr/lib/x86_64-linux-gnu/libKF5Archive.so.5)
kde-open5: /home/<user>/Qt/5.10.0/gcc_64/lib/libQt5Core.so.5: version `Qt_5.11' not found (required by /usr/lib/x86_64-linux-gnu/libKF5ItemViews.so.5)
kde-open5: /home/<user>/Qt/5.10.0/gcc_64/lib/libQt5Core.so.5: version `Qt_5.11' not found (required by /usr/lib/x86_64-linux-gnu/libKF5Codecs.so.5)
kde-open5: /home/<user>/Qt/5.10.0/gcc_64/lib/libQt5Core.so.5: version `Qt_5.11' not found (required by /usr/lib/x86_64-linux-gnu/libKF5GuiAddons.so.5)

AFAIK上面提到的两条路径是相互并发的,因为一条是由分布创建的,一条是由Qt Creator创建的。

解决方案应该在链接应用程序时使用-rpath。我的应用程序使用以下命令行构建:

gcc -Wl,-rpath,/home/<user>/Qt/5.10.0/gcc_64/lib .....

对我来说很好看。以下内容也传递给gcc:

-L/home/<user>/Qt/5.10.0/gcc_64/lib

这里缺少什么?为什么我的应用程序依赖于Qt 5.11库,而构建过程设置了正确的Qt 5.10路径?

更新,这是ldd关于我的可执行文件的说法。

linux-vdso.so.1 =>  (0x00007ffd08b1e000)
libQt5Widgets.so.5 => /home/<user>/Qt/5.10.0/gcc_64/lib/libQt5Widgets.so.5 (0x00007faa1849b000)
libQt5Gui.so.5 => /home/<user>/Qt/5.10.0/gcc_64/lib/libQt5Gui.so.5 (0x00007faa17cb3000)
libQt5DBus.so.5 => /home/<user>/Qt/5.10.0/gcc_64/lib/libQt5DBus.so.5 (0x00007faa17a23000)
libQt5Xml.so.5 => /home/<user>/Qt/5.10.0/gcc_64/lib/libQt5Xml.so.5 (0x00007faa177e3000)
libQt5Script.so.5 => /home/<user>/Qt/5.10.0/gcc_64/lib/libQt5Script.so.5 (0x00007faa1735b000)
libQt5XmlPatterns.so.5 => /home/<user>/Qt/5.10.0/gcc_64/lib/libQt5XmlPatterns.so.5 (0x00007faa16d83000)
libQt5Network.so.5 => /home/<user>/Qt/5.10.0/gcc_64/lib/libQt5Network.so.5 (0x00007faa169eb000)
libQt5Core.so.5 => /home/<user>/Qt/5.10.0/gcc_64/lib/libQt5Core.so.5 (0x00007faa1629b000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007faa1607b000)
libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007faa15cf3000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007faa159e3000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007faa157cb000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007faa153fb000)
/lib64/ld-linux-x86-64.so.2 (0x00007faa18cdb000)
libGL.so.1 => /usr/lib/x86_64-linux-gnu/mesa/libGL.so.1 (0x00007faa15183000)
libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007faa14f63000)
libdbus-1.so.3 => /lib/x86_64-linux-gnu/libdbus-1.so.3 (0x00007faa14d13000)
libicui18n.so.56 => /home/<user>/Qt/5.10.0/gcc_64/lib/libicui18n.so.56 (0x00007faa14873000)
libicuuc.so.56 => /home/<user>/Qt/5.10.0/gcc_64/lib/libicuuc.so.56 (0x00007faa144bb000)
libicudata.so.56 => /home/<user>/Qt/5.10.0/gcc_64/lib/libicudata.so.56 (0x00007faa12ad3000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007faa128cb000)
libgthread-2.0.so.0 => /usr/lib/x86_64-linux-gnu/libgthread-2.0.so.0 (0x00007faa126c3000)
libglib-2.0.so.0 => /lib/x86_64-linux-gnu/libglib-2.0.so.0 (0x00007faa123ab000)
libexpat.so.1 => /lib/x86_64-linux-gnu/libexpat.so.1 (0x00007faa1217b000)
libxcb-dri3.so.0 => /usr/lib/x86_64-linux-gnu/libxcb-dri3.so.0 (0x00007faa11f73000)
libxcb-present.so.0 => /usr/lib/x86_64-linux-gnu/libxcb-present.so.0 (0x00007faa11d6b000)
libxcb-sync.so.1 => /usr/lib/x86_64-linux-gnu/libxcb-sync.so.1 (0x00007faa11b63000)
libxshmfence.so.1 => /usr/lib/x86_64-linux-gnu/libxshmfence.so.1 (0x00007faa1195b000)
libglapi.so.0 => /usr/lib/x86_64-linux-gnu/libglapi.so.0 (0x00007faa1172b000)
libXext.so.6 => /usr/lib/x86_64-linux-gnu/libXext.so.6 (0x00007faa11513000)
libXdamage.so.1 => /usr/lib/x86_64-linux-gnu/libXdamage.so.1 (0x00007faa1130b000)
libXfixes.so.3 => /usr/lib/x86_64-linux-gnu/libXfixes.so.3 (0x00007faa11103000)
libX11-xcb.so.1 => /usr/lib/x86_64-linux-gnu/libX11-xcb.so.1 (0x00007faa10efb000)
libX11.so.6 => /usr/lib/x86_64-linux-gnu/libX11.so.6 (0x00007faa10bbb000)
libxcb-glx.so.0 => /usr/lib/x86_64-linux-gnu/libxcb-glx.so.0 (0x00007faa1099b000)
libxcb-dri2.so.0 => /usr/lib/x86_64-linux-gnu/libxcb-dri2.so.0 (0x00007faa10793000)
libxcb.so.1 => /usr/lib/x86_64-linux-gnu/libxcb.so.1 (0x00007faa1056b000)
libXxf86vm.so.1 => /usr/lib/x86_64-linux-gnu/libXxf86vm.so.1 (0x00007faa10363000)
libdrm.so.2 => /usr/lib/x86_64-linux-gnu/libdrm.so.2 (0x00007faa1014b000)
libsystemd.so.0 => /lib/x86_64-linux-gnu/libsystemd.so.0 (0x00007faa18e43000)
libpcre.so.3 => /lib/x86_64-linux-gnu/libpcre.so.3 (0x00007faa0fedb000)
libXau.so.6 => /usr/lib/x86_64-linux-gnu/libXau.so.6 (0x00007faa0fcd3000)
libXdmcp.so.6 => /usr/lib/x86_64-linux-gnu/libXdmcp.so.6 (0x00007faa0facb000)
libselinux.so.1 => /lib/x86_64-linux-gnu/libselinux.so.1 (0x00007faa0f8a3000)
librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007faa0f69b000)
liblzma.so.5 => /lib/x86_64-linux-gnu/liblzma.so.5 (0x00007faa0f473000)
libgcrypt.so.20 => /lib/x86_64-linux-gnu/libgcrypt.so.20 (0x00007faa0f18b000)
libgpg-error.so.0 => /lib/x86_64-linux-gnu/libgpg-error.so.0 (0x00007faa0ef73000)

UPDATE2,/sbin/ldconfig -v 2>/dev/null | grep -v ^$'\t'导致:

/usr/lib/x86_64-linux-gnu/libfakeroot:
/lib/i386-linux-gnu:
/usr/lib/i386-linux-gnu:
/usr/lib/i386-linux-gnu/mesa:
/usr/local/lib:
/lib/x86_64-linux-gnu:
/usr/lib/x86_64-linux-gnu:
/usr/lib/x86_64-linux-gnu/mesa-egl:
/usr/lib/x86_64-linux-gnu/mesa:
/lib:
/usr/lib:
/usr/lib/i386-linux-gnu/sse2: (hwcap: 0x0000000004000000)

echo $LD_LIBRARY_PATH不打印任何内容。

1 个答案:

答案 0 :(得分:1)

-rpath对可执行文件或库中的 r 非时间库搜索路径进行了硬编码。它不会影响链接器搜索路径,因此您的应用程序与系统Qt库链接。您应该通过-L选项传递相同的路径:

gcc -Wl,-rpath,/home/<user>/Qt/5.10.0/gcc_64/lib -L/home/<user>/Qt/5.10.0/gcc_64/lib ...

以下是更多信息:

Why is -L needed when -rpath is used?

What's the difference between -rpath and -L?