2012-03-15 31 views
7

已經安裝了android-ndk-r7,並試圖編譯.cpp文件。無法在android中包含iostream爲什麼?

#include <iostream> 

using namespace std; 

int main (int argc, char ** argv) 
{ 

    cout <<"Hello World.."<<endl; 

} 

已執行以下命令: 鑽進JNI的文件夾,並執行

#ndk-build 

了以下錯誤:

/home/jelari/Desktop/androidDevelopment/android-ndk-r7/DCF/jni/test1.cpp:1:20: error: iostream: No such file or directory 
/home/jelari/Desktop/androidDevelopment/android-ndk-r7/DCF/jni/test1.cpp: In function 'int main(int, char**)': 
/home/jelari/Desktop/androidDevelopment/android-ndk-r7/DCF/jni/test1.cpp:8: error: 'cout' was not declared in this scope 
/home/jelari/Desktop/androidDevelopment/android-ndk-r7/DCF/jni/test1.cpp:8: error: 'endl' was not declared in this scope 
make: *** [/home/jelari/Desktop/androidDevelopment/android-ndk-r7/DCF/obj/local/armeabi/objs/test1/test1.o] Error 1 

我到底做錯了什麼?

我Android.mk文件看起來像:

# A simple test for the minimal standard C++ library 
# 

LOCAL_PATH := $(call my-dir) 

include $(CLEAR_VARS) 
LOCAL_MODULE := test1 
LOCAL_SRC_FILES := test1.cpp 
include $(BUILD_EXECUTABLE) 

和Application.mk文件看起來像:

# Build both ARMv5TE and ARMv7-A machine code. 
APP_ABI := armeabi armeabi-v7a 

請指出錯誤了嗎?

+0

@Nick,可恥的是我:(添加此。建議立即進行刪除d已經做到了,而不是打字。抱歉!!。 – Whoami 2012-03-15 14:36:35

+0

啊哈哈哈哈 - 我們都做到了! – Nick 2012-03-15 14:37:09

回答

3

另一種方法是引用

By default, the C++ standard library is very minimal.

You need to set APP_STL in your Application.mk file.

I use:

APP_STL := gnustl_static

but you could have used system, stlport_static, stlport_shared, or gnustl_static.

It's documented under $NDK/docs/CPLUSPLUS-SUPPORT.html, and it's a little hidden, because the $NDK/documentation.html index file doesn't list it.

,如果你沒有application.mk和android.mk文件,

在你的build.gradle

ndk{ 
    moduleName = your_module_name 
    stl = "c++_static" 
} 
相關問題