Android的性病和STL支持性病、Android、STL

2023-09-12 11:13:04 作者:橘裏〓路亽

我玩了Android NDK。我使用的Windows Vista上使用Cygwin的(最新版)。我编写并推出的hello world JNI样品在我的手机。这是工作。在code是(是一个.cpp文件):

I am playing with android ndk. I am using Window Vista with cygwin (latest version). I compiled and launched the hello world jni sample on my phone. It is working. The code is (is a .cpp file):

#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!");
} 

我想补充一些修改,只需用它打了一下:

I wanted to add some modifications, just to play with it a bit:

#include <algorithm>

然后,在功能上面,我说:

and then, in the function above, i added:

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

但是编译器说,它无法找到文件'算法'和MIN()是不是性病的一部分。

but the compiler says that it cannot find the file 'algorithm' and that min() is not part of std.

在进行位的搜索,我发现了Android NDK具有的GNU的libstdc ++目录提供一切必要的STD文件。读NDK的文档,我已经学会了USINT的std :: *应该没有任何修改的code(如果包括适当的头文件)。但似乎海湾合作委员会在Cygwin上是无法找到所需的文件。

After a bit of searching, i have found that the android ndk has a gnu-libstdc++ directory with all the std files needed. Reading the NDK docs, i have learned that usint std::* should work without any modification to the code (if one include the proper header files). But it seems that gcc on cygwin is not able to find the needed files.

有哪些步骤做,以便能够在Android NDK应用程序中使用内.cpp文件性病和STL?

What are the steps to do in order to be able to use std and stl within a .cpp file in an android ndk app?

推荐答案

从NDK R5的文档/ CPLUSPLUS-SUPPORT.html:

From NDK r5's docs/CPLUSPLUS-SUPPORT.html:

默认情况下,头文件和库的最低C ++运行时系统   库(/system/lib/libstdc++.so)正在构建C ++源代码时使用。

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

但是,您可以通过设置变量选择不同的实现   APP_STL在你Application.mk别的东西,例如:

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

APP_STL := stlport_static

要选择具有该NDK静态STLport实现。   价值APP_STL值如下:

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

系统 - >使用默认的最小的C ++运行时库      stlport_static - >使用的STLport建成一个静态库。      stlport_shared - >使用的STLport作为共享库      gnustl_static - >使用GNU的libstdc ++作为静态库

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如测试的libstdc ++?

Which NDK are you using? Have you tried compiling one of the sample applications that utilize the STL such as test-libstdc++?