为Android构建的C ++库使用了错误的依赖性符号

时间:2019-06-03 23:43:09

标签: android c++

当我使用独立工具链构建C ++库时,它可以成功编译,但是在运行时失败,并且依赖库的符号未定义:

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的std库实现,但是需要更好的理解。

2)为什么我的图书馆不使用它?我尝试将-static-libstdc++传递给LDFLAGS-DANDROID_STL=c++_static-DANDROID_STL=c++_shared都没有运气。如何强制我的图书馆使用正确的符号?

1 个答案:

答案 0 :(得分:1)

我在Ubuntu 14和16之间遇到了这个问题。原因是GCC和运行时ABI的版本。 This GCC documentation page说明了如何使用_GLIBCXX_USE_CXX11_ABI宏来控制链接器的查找内容。