问题
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