Android NDK + Two Shared Libraries + RTTI + Dynamic cast = Impossible

心不动则不痛 提交于 2021-01-29 14:26:28

问题


I've been at this for 4 hours so far on a Sunday. I'm about to give up. I've tried literally every post I've found on the internet and this simply will..not..work!

Any instance of dynamic_cast with references or pointers either returns null or flat-out crashes my program. This is absolutely 100% critical to my entire application architecture, and I may just have to go to 200 MB static libs if I can't get this going.

I'm building with -frtti (there's no -fno-rtti), and linking with -Wl,-export-dynamic (also tried rdynamic) on all my libraries.

I've also manually overrode Java's loadLibrary() by using my own dlopen(fn, RTLD_NOW | RTLD_GLOBAL) to open each lib (I've tried every possible combination of flags.

Is this simply not possible? Leave it to android to take something that has worked well for me for an entire decade on other platforms and turn it into a huuuuge problem that cannot be solved.


回答1:


This is probably https://android.googlesource.com/platform/ndk/+/master/docs/user/common_problems.md#rtti_exceptions-not-working-across-library-boundaries. The C++ ABI makes it tricky to get RTTI right when dynamically loading libraries. Each of your types must have a key function (a virtual, non-inline, non-destructor method) for RTTI to work across shared library boundaries.



来源:https://stackoverflow.com/questions/56420705/android-ndk-two-shared-libraries-rtti-dynamic-cast-impossible

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