android - 如果我的代码使用 RTTI 那么它不能在 android 上运行?

标签 android c++ java-native-interface rtti

我在 Android Native Development Kit Cookbook 中读到:

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.

如果在应用程序的逻辑中使用了 RTTI 那么它就不能在 android 上运行吗?

最佳答案

您可以打开它,默认情况下它是关闭的。要打开它,请将 LOCAL_CPPFLAGS += -frtti 添加到您的 makefile。与往常一样,打开此标志的代码将占用更多内存,磁盘空间更大,并且比关闭它的代码稍微慢一些。

关于android - 如果我的代码使用 RTTI 那么它不能在 android 上运行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23976633/

相关文章:

java - 解释用户文本输入的更好方法

C# 用于 UI,C++ 用于库

c++ - 在 C++ 中初始化对象

java - 来自 C++ 的 JNI 调用、FindClass 和导入

java - JNI 中的二维数组

java - 安卓。如何在带有显示切口的设备上以编程方式正确隐藏状态栏

Android,静音模式通知

c++ - xxx.h : fatal error C1083: Cannot open include file: 'yyyy.h' : No such file or directory

android - 方法签名与实际调用不匹配

android - GrantPermissionRule 授予权限失败