Symbol lookup error undefined symbol, but all symbols seem to be present

一曲冷凌霜 提交于 2019-12-11 05:04:45

问题


An executable seemingly can't resolve a symbol in a linked library. The relevant output of LD_DEBUG=libs shows that the correct library is loaded: 6557: /usr/lib/libcharon.so.0: error: symbol lookup error: undefined symbol: auth_class_names (fatal) /usr/libexec/ipsec/charon: symbol lookup error: /usr/lib/libcharon.so.0: undefined symbol: auth_class_names

nm -D shows that the symbol auth_class_names is defined:

nm -D /usr/lib/libcharon.so.0|grep auth_class_names U auth_class_names

All clues and ideas welcome

EDIT: Outputs of ldd added:

/usr/lib# ldd /usr/lib/libstrongswan.so
    libpthread.so.0 => /lib/arm-linux-gnueabi/libpthread.so.0 (0xb6ecd000)
    libdl.so.2 => /lib/arm-linux-gnueabi/libdl.so.2 (0xb6ec2000)
    librt.so.1 => /lib/arm-linux-gnueabi/librt.so.1 (0xb6eb3000)
    libc.so.6 => /lib/arm-linux-gnueabi/libc.so.6 (0xb6d78000)
    /lib/ld-linux.so.3 (0xb6f25000)
/usr/lib# ldd /usr/lib/libcharon.so
    libm.so.6 => /lib/arm-linux-gnueabi/libm.so.6 (0xb6ea6000)
    libpthread.so.0 => /lib/arm-linux-gnueabi/libpthread.so.0 (0xb6e86000)
    libdl.so.2 => /lib/arm-linux-gnueabi/libdl.so.2 (0xb6e7b000)
    libcap.so.2 => /lib/arm-linux-gnueabi/libcap.so.2 (0xb6e70000)
    libc.so.6 => /lib/arm-linux-gnueabi/libc.so.6 (0xb6d35000)
    /lib/ld-linux.so.3 (0xb6fa6000)
    libattr.so.1 => /lib/arm-linux-gnueabi/libattr.so.1 (0xb6d27000)

# nm -D /usr/lib/libstrongswan.so|grep auth_class
00036a50 D auth_class_names

回答1:


nm -D shows that the symbol auth_class_names is defined

No: it shows that auth_class_names is undefined in libcharon.so.

libstrongswan provides the auth_class symbol, but libcharon doesn't reference it.

Wrong again: libcharon.so does reference the symbol.

ldd /usr/lib/libstrongswan.so

That's not what you want. You want ldd /usr/lib/libcharon.so.

Your problem is most likely that neigher libcharon.so, nor the main executable were linked against libstrongswan.so, so when you dynamically load libcharon.so, libstrongswan.so is nowhere to be found; hence the loading fails with undefined symbol.

There are several possible solutions, ordered from more correct to more hacky:

  1. Link libcharon.so against libstrongswan.so. Loading libcharon.so will load all of its dependencies (which will now include libstrongswan.so, and the symbol will be found).

  2. Link charon binary against libstrongswan.so.

  3. Dynamically load libstrongswan.so before you load libcharon.so.
  4. LD_PRELOAD=libstrongswan.so



回答2:


Actually "U" means, that symbol is undefined. What does ldd show on your libcharon.so.0? libstrongswan.so.0 is where you should find auth_class_names.



来源:https://stackoverflow.com/questions/50688237/symbol-lookup-error-undefined-symbol-but-all-symbols-seem-to-be-present

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!