Android std 和 stl 支持 [英] Android std and stl support

查看:17
本文介绍了Android std 和 stl 支持的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在玩 android ndk.我正在使用带有 cygwin(最新版本)的 Window Vista.我在手机上编译并启动了 hello world jni 示例.这是工作.代码是(是一个.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() 不是 std 的一部分.

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::* 应该可以在不修改代码的情况下工作(如果包含正确的头文件).但是cygwin上的gcc似乎找不到需要的文件.

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 文件中使用 std 和 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 的 docs/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:

system -> 使用默认的最小 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 的示例应用程序之一,例如 test-libstdc++?

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

这篇关于Android std 和 stl 支持的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆