不能包括C ++头文件,如向量的Andr​​oid NDK [英] Can't include C++ headers like vector in Android NDK

查看:138
本文介绍了不能包括C ++头文件,如向量的Andr​​oid NDK的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试包括任何C ++类像载体在我的Andr​​oid NDK的项目(使用NDK R5B,最新的),我得到如下所示的错误...

When I try to include any C++ class like vector in my Android NDK project (using NDK r5b, the latest), I get an error like the following...

++编译大拇指:测试libstl< =测试libstl.cpp /Users/nitrex88/Desktop/Programming/EclipseProjects/STLTest/jni/test-libstl.cpp:3:18:错误:向量:没有这样的文件或目录

Compile++ thumb : test-libstl <= test-libstl.cpp /Users/nitrex88/Desktop/Programming/EclipseProjects/STLTest/jni/test-libstl.cpp:3:18: error: vector: No such file or directory

谁在线报道这个问题有人称成功加入其它人

Other people who reported this issue online have claimed success by adding

APP_STL:= stlport_static

他们Application.mk文件。我已经做到了这一点,以及审判APP_STL所有其他可能的值。我已经清理项目,跑NDK,打造干净,删除的OBJ文件和库文件夹,仍然当我编译它找不到vector类。我一直都在为这几个星期,现在(因为NDK R5出来了),希望如果有人有什么建议真的AP preciate。谢谢!

to their Application.mk file. I have done this as well as tried every other possible value for APP_STL. I've cleaned to project, ran ndk-build clean, deleted the obj and libs folders, and still when I compile it cannot find the vector class. I've been working on this for a number of weeks now (since NDK r5 came out) and would really appreciate if someone has any advice. Thanks!

推荐答案

这是可能的。下面是一些一步一步:

It is possible. Here is some step by step:

$ PROJECT_DIR / JNI / Application.mk

APP_STL                 := stlport_static

我试着用stlport_shared,但没有运气。同样的,的libstdc ++。

I tried using stlport_shared, but no luck. Same with libstdc++.

$ PROJECT_DIR / JNI / Android.mk

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE    := hello-jni
LOCAL_SRC_FILES := hello-jni.cpp
LOCAL_LDLIBS    := -llog

include $(BUILD_SHARED_LIBRARY)

这里没有什么特别,但要确保你的文件的的.cpp

$ PROJECT_DIR / JNI / HELLO-jni.cpp

#include <string.h>
#include <jni.h>
#include <android/log.h>

#include <iostream>
#include <vector>


#define  LOG_TAG    "hellojni"
#define  LOGI(...)  __android_log_print(ANDROID_LOG_INFO,LOG_TAG,__VA_ARGS__)
#define  LOGE(...)  __android_log_print(ANDROID_LOG_ERROR,LOG_TAG,__VA_ARGS__)


#ifdef __cplusplus
extern "C" {
#endif

// Comments omitted.    
void
Java_com_example_hellojni_HelloJni_stringFromJNI( JNIEnv* env,
                                                  jobject thiz )
{
    std::vector<std::string> vec;

    // Go ahead and do some stuff with this vector of strings now.
}

#ifdef __cplusplus
}
#endif

唯一令咬在这里我是的#ifdef __cplusplus。

The only thing that bite me here was #ifdef __cplusplus.

观看目录。

要编译,使用 NDK-建立清洁和放大器;&安培; NDK建造

这篇关于不能包括C ++头文件,如向量的Andr​​oid NDK的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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