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

Android Application.mk settings to be able to use c++11 <random> and dynamic_cast

在 Application.mk 文件中,当使用 APP_STL := stlport_static 我可以使用 c++11 dynamic_cast 但它不会编译 "random" 功能。

我试过 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 用来执行 run-time 类型检查。

引用自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