Android std和stl支持

我正在玩 android ndk.我正在使用 Windows Vista与cygwin(最新版本).我在手机上编译并推出了你好的世界jni样本.这是工作.代码是(是.cpp文件):
#include <string.h>
#include <jni.h>

extern "C" {
JNIEXPORT jstring JNICALL     Java_org_android_helloworld_HelloworldActivity_invokeNativeFunction(jnienv* env,jobject     javaThis);
};


jstring Java_org_android_helloworld_HelloworldActivity_invokeNativeFunction(jnienv*     env,jobject javaThis)
{
    return  env->NewStringUTF("Hello from native code!");
}

我想添加一些修改,只是为了玩一下:

#include <algorithm>

然后,在上面的功能中,我补充说:

int a;
a=std::min<int>(10,5);

但编译器却说找不到文件’algorithm’,而min()不是std的一部分.

经过一番搜索,我发现android ndk有一个gnu-libstdc目录,其中包含所有std文件.阅读NDK文档,我已经了解到,usint std :: *应该没有任何修改代码(如果包括正确的头文件).但似乎cygwin上的gcc无法找到所需的文件.

为了能够在android ndk应用程序中的.cpp文件中使用std和stl,需要执行哪些步骤?

解决方法

来自NDK r5的文档/ CPLUSPLUS-SUPPORT.html:

By default,the headers and libraries for the minimal C++ runtime system
library (/system/lib/libstdc++.so) are used when building C++ sources.

You can however select a different implementation by setting the variable
APP_STL to something else in your Application.mk,for example:

APP_STL := stlport_static

To select the static STLport implementation provided with this NDK.
Value APP_STL values are the following:

system -> Use the default minimal C++ runtime library.
stlport_static -> Use STLport built as a static library.
stlport_shared -> Use STLport built as a shared library.
gnustl_static -> Use GNU libstdc++ as a static library.

你使用哪个NDK?您是否尝试编译使用STL的示例应用程序之一,如test-libstdc?

相关文章

Android性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...