在 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
使用它来执行运行时类型检查。
[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/