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

标签 android c++

当我使用独立工具链构建我的 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/

相关文章:

android - 如果设置 -> 显示 -> 显示大小更改为大或小,则禁用应用程序或 Activity 缩放

android - 在 Android 中创建模态日期选择器对话框

android - 如何在android-ndk项目中使用C++类

c++ Sentinel循环,存储最小和最大数字

android - 需要一个 Android 中的 HttpResponseCache 的例子

php - 如何在另一个文件中执行后使用php变量的值

c++ - 生成一个小于 4 位的随机数,但它具有 1、2 或 3 位的概率相等

c++ - 如何使用 boost::spirit 验证代数语句?

c++ - 从 C++ 中的另一个 .exe 生成用户自定义的 .exe

c++ - 警告 : offset of on non-standard-layout type 'DerivedClass'