当我使用独立工具链构建我的 C++ 库时,它编译成功但在运行时失败,并显示依赖库的 undefined symbol :
06-03 15:16:29.554 3599 3619 D Unity : Unable to load library '/data/app/com.x.y.z.app-_VFxANKGcCeB5wdqbLmvgQ==/lib/arm/libmylib.so', native render plugin support disabled: java.lang.UnsatisfiedLinkError: dlopen failed: cannot locate symbol "_ZN3ndn18MemoryContentCache4Impl26getPendingInterestsForNameERKNS_4NameERSt6vectorISt10shared_ptrIKNS0_15PendingInterestEESaIS9_EE" referenced by "/data/app/com.ux.y.z.app
未损坏的符号是 ndn::MemoryContentCache::Impl::getPendingInterestsForName(ndn::Name const&, std::vector<std::shared_ptr<ndn::MemoryContentCache::PendingInterest const>, std::allocator<std::shared_ptr<ndn::MemoryContentCache::PendingInterest const> > >&)
.
依赖库中确实缺少此符号,相反,此符号存在:_ZN3ndn18MemoryContentCache4Impl26getPendingInterestsForNameERKNS_4NameERNSt6__ndk16vectorINS5_10shared_ptrIKNS0_15PendingInterestEEENS5_9allocatorISA_EEEE
这是ndn::MemoryContentCache::Impl::getPendingInterestsForName(ndn::Name const&, std::__ndk1::vector<std::__ndk1::shared_ptr<ndn::MemoryContentCache::PendingInterest const>, std::__ndk1::allocator<std::__ndk1::shared_ptr<ndn::MemoryContentCache::PendingInterest const> > >&)
.
可以看出,依赖库使用std::__ndk1::vector
类,而我的库只用 std::vector
编译.
因此,问题:
1) 什么是 __ndk1
字首?我相信这是 NDK 的标准库实现,但需要更好地理解。
2) 为什么我的图书馆不使用它?我试着通过 -static-libstdc++
至 LDFLAGS
或 -DANDROID_STL=c++_static
和 -DANDROID_STL=c++_shared
没有运气。如何强制我的图书馆使用正确的符号?
最佳答案
我在 Ubuntu 14 和 16 之间遇到过这个问题,原因是 GCC 的版本和运行时 ABI。 This GCC documentation page解释了如何使用 _GLIBCXX_USE_CXX11_ABI
宏来控制链接器查找的内容。
关于android - 为 Android 构建的 C++ 库使用了错误的依赖符号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56435764/