设为首页 加入收藏

TOP

Android NDK 中使用STL
2014-11-24 00:15:00 来源: 作者: 【 】 浏览:3
Tags:Android NDK 使用 STL

1. 例子工程目录结构:
test-libstdc++ / jni / Android.mk
test-libstdc++ / jni / Application.mk
test-libstdc++ / jni / test-libstdc++.cpp


2. Android.mk文件:


# A simple test for the minimal standard C++ library
#
LOCAL_PATH := $(call my-dir)


include $(CLEAR_VARS)
LOCAL_MODULE := test-libstl
LOCAL_SRC_FILES := test-libstl.cpp
LOCAL_LDLIBS := -llog


include $(BUILD_EXECUTABLE)


include $(CLEAR_VARS)
LOCAL_EXECUTABLE := test-libstl


3. Application.mk内容:


APP_STL := stlport_static


4. test-libstdc++.cpp内容:


#include
#include
#include
using namespace std;


int main() {
vector contents;
for (int i=0; i<5; i++)
{
contents.push_back(string("vector"));
}

for (int i=0; i<5; i++)
{
cout << contents[i] << endl;
}

cout << "hello, world\n";
return 0;
}


5. 最后在test-libstdc++\libs\armeabi目录下面生成test-libstl 可执行程序。原理类似tcpdump工具使用,通过adb推到手机上,在shell模式下运行改可执行程序:


D:\android-sdk-windows\platform-tools>adb push test-libstl /data/local/
1341 KB/s (251396 bytes in 0.182s)


D:\android-sdk-windows\platform-tools>adb shell chmod 755 /data/local/test-libstl


D:\android-sdk-windows\platform-tools>adb shell /data/local/test-libstl
vector
vector
vector
vector
vector
hello, world


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇OpenGL纹理UV动画 下一篇基于OpenGL的RoundBox绘制

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: