If my code uses RTTI then it will not work on android?

安稳与你 提交于 2020-01-04 02:45:09

问题


I read in Android Native Development Kit Cookbook that:

By default, Android provides minimal C++ support. There's no Run-time Type Information (RTTI) and C++ exceptions support, and even the C++ standard library support, is partial. The following is a list of the C++ headers supported by Android NDK by default:

cassert, cctype,cerrno, cfloat, climits, cmath, csetjmp, csignal, cstddef, cstdint, cstdio, cstdlib, cstring, ctime, cwchar, new, stl_pair.h, typeinfo, utility

It is possible to add more C++ support by using different C++ libraries. NDK comes with the gabi++, stlport, and gnustl C++ libraries, besides the system default one. In our sample code, we used an external "C" to wrap the C++ method. This is to avoid C++ mangling of the JNI function names. C++ name mangling could change the function names to include type information about parameters, whether the function is virtual or not, and so on. While this enables C++ to link overloaded functions, it breaks the JNI function discovery mechanism.

We can also use the explicit function registration method covered in the Loading native libraries and registering native methods recipe of Chapter 2, Java Native Interface, to get rid of the wrapping.

If RTTI is used in the logic of the application then it will not work on android?


回答1:


You can turn it on, its off by default. To turn it on, add LOCAL_CPPFLAGS += -frtti to your makefile. As usual, code with this flag on will take more memory, be bigger on disk, and be slightly slower than code with it off.



来源:https://stackoverflow.com/questions/23976633/if-my-code-uses-rtti-then-it-will-not-work-on-android

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