Android JNI: Can't include C++ headers like vector or string...
2016-04-22 09:24
387 查看
错误如下:
fatal error: string: No such file or directory
#include <string>
^
compilation terminated.
修正:
第一步:
在 $PROJECT_DIR/jni/Application.mk: 加入
第二步:
在 $PROJECT_DIR/jni/Android.mk:
第三步:
在 $PROJECT_DIR/jni/hello-jni.cpp:
fatal error: string: No such file or directory
#include <string>
^
compilation terminated.
修正:
第一步:
在 $PROJECT_DIR/jni/Application.mk: 加入
APP_STL := stlport_static
第二步:
在 $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)
第三步:
在 $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
然后
ndk-build clean && ndk-build.
相关文章推荐
- 【C++】Geekband-专题二:虚指针和内存分配
- 【C++】Geekband-专题三:const
- C++标准模板库
- C或C++ 求两个数组相同元素个数
- C++实践参考解答:我的数组类
- 第4章 C语言及程序设计提高例程-21 首尝排序——冒个泡
- 第4周 C语言及程序设计提高例程-20 经典:查找的艺术
- Power of Four leetcode 342
- 【C/C++】使用预编译命令时犯下的一个错误
- (LeetCode 15) 3Sum
- 【C++】static_cast, dynamic_cast, reinterpret_cast, const_cast区别比较
- Win7下的C语言开发环境
- 基于C++标准map的多线程安全容器mymap::map进化版
- C/C++中结构体引用中箭头->与点.的区别
- C++知识点积累(2)
- C++第四次上机实验
- C++第四次上机作业
- c++第4次作业
- [c++]set整理
- C语言问卷调查