如果我的code使用RTTI,那么它不会在Android上工作? [英] If my code uses RTTI then it will not work on android?

查看:139
本文介绍了如果我的code使用RTTI,那么它不会在Android上工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我Android原生开发套件食谱,上面写着


  

在默认情况下,Android提供最小的C ++的支持。有没有运行时
  类型信息(RTTI)和C ++异常的支持,甚至C ++
  标准库的支持,是局部的。以下是对一个列表
  默认情况下,由Android NDK支持C ++头文件:


  
  

了cassert,cctype,cerrno,cfloat,climits,CMATH,csetjmp,csignal,cstddef,cstdint,
  cstdio,cstdlib,CString的,的ctime,cwchar,新,stl_pair.h,所属类别,效用


  
  

这可以通过使用不同的C添加更多的C ++支持++
  库。 NDK自带的加比++,STLport的,和gnustl C ++
  图书馆,除了系统默认之一。在我们的样本code,我们使用
  外部C来包装C ++方法。这是为了避免C ++识别码
  的JNI函数名。 C ++名称重整可能会改变功能
  名称包括有关参数类型的信息,无论是
  函数是虚拟与否,等等。虽然这使C ++链接
  重载函数,它打破了JNI函数发现机制。


  
  

我们也可以使用覆盖的显函数注册方法
  加载本地库和注册本地方法的食谱
  第2章,Java本地接口,摆脱了包装的。


如果RTTI在应用程序的逻辑中使用,那么它不会在Android上工作?


解决方案

您可以在默认情况下打开它,它的关闭。要打开它,添加 LOCAL_CPPFLAGS + = -frtti 来你的makefile。像往常一样,code。与此标志将带更多的内存,更大的硬盘,比code稍慢它关闭。

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?

解决方案

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.

这篇关于如果我的code使用RTTI,那么它不会在Android上工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆