#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,需要执行哪些步骤?
解决方法
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?