Android ndk 中使用STL

來源:互聯網
上載者:User

ndk版本:android-ndk-r8d,基於ndk內建samples中的test-libstdc++工程進行修改。

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-libstlLOCAL_SRC_FILES := test-libstl.cppLOCAL_LDLIBS    := -lloginclude $(BUILD_EXECUTABLE)include $(CLEAR_VARS)LOCAL_EXECUTABLE := test-libstl

3. Application.mk內容:

APP_STL := stlport_static

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

#include <iostream>#include <string>#include <vector>using namespace std;int main() {vector<string> 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-libstlD:\android-sdk-windows\platform-tools>adb shell /data/local/test-libstlvectorvectorvectorvectorvectorhello, world

參考:http://tungchingkai.blogspot.com/2011/08/how-to-build-android-ndk-sample-using.html

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.