Android Application.mk 设置能够使用 c++11 <random> 和 dynamic_cast

标签 android c++11 random java-native-interface dynamic-cast

在 Application.mk 文件中,当使用 APP_STL := STLport_static 时,我可以使用 c++11 dynamic_cast 但它不会编译“随机”功能。

我试过 APP_STL := gnuSTL_static 和 APP_STL := c++_static 但它们不允许我使用 dynamic_cast。

为了能够同时使用两者,Application.mk 的正确设置是什么?

我当前的 Application.mk 看起来像:

APP_CPPFLAGS += -std=c++11
APP_STL := stlport_static 
APP_ABI := armeabi armeabi-v7a x86

编辑:

最后,按照 Michaels 的指示,有效的 Application.mk 是:

#LIBCXX rebuild was needed once when using APP_STL := c++_static
LIBCXX_FORCE_REBUILD := true
APP_CPPFLAGS += -std=c++11 -frtti -fexceptions
APP_STL := c++_static
#Also the gnu compiler can be used
#APP_STL:= gnustl_static
APP_ABI := armeabi armeabi-v7a x86
NDK_TOOLCHAIN_VERSION := 4.8

最佳答案

听起来您好像忘记启用 RTTI,dynamic_cast 使用它来执行运行时类型检查。

引自the documentation :

[To] ensure compatibility with earlier releases, [the NDK toolchain] compiles all C++ sources with -fno-rtti by default.

To enable RTTI support for your entire app for your entire application, add the following line to your Application.mk file:

APP_CPPFLAGS += -frtti

我在 STLport 源中没有看到任何 random header ,因此它可能不支持该功能。请改用其他 STL 实现,例如 gnuSTL。

所以你需要的是:

APP_CPPFLAGS += -std=c++11 -frtti
APP_STL := gnustl_static 

关于Android Application.mk 设置能够使用 c++11 <random> 和 dynamic_cast,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34868104/

相关文章:

c++ - 实现一个类似于 Qt 的高性能互斥锁

data.table 中跨组(不在组内)随机排序

javascript - 循环检查数组中的最后一个图像

java - 当 EditText 为空且按下按钮时 Android 应用程序崩溃

android - android 约束布局 1.1.3 的组可见性不起作用

c++ - 限制可变参数函数模板仅接受一个可变参数类模板的嵌套可变参数类模板的变体?

C++11 在 std::is_same 之后调用类型的构造函数以确认其类型

javascript - 从 API 随机生成国家/地区名称

android - 自定义 SimpleCursorAdapter 和 BindView(按钮随机不可见)

android - Firebase 动态链接打开特定 Activity