2012-03-15 25 views
7

Đã cài đặt android-ndk-r7 và cố gắng biên dịch tệp .cpp.Không thể đưa iostream vào android tại sao?

#include <iostream> 

using namespace std; 

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

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

} 

đã thi lệnh sau: Got vào thư mục JNI, và thực hiện

#ndk-build 

Got lỗi sau:

/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 

am i làm gì sai?

tập tin của tôi Android.mk trông giống như:

# 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) 

và Application.mk tập tin trông giống như:

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

Vui lòng chỉ ra những sai lầm?

+0

@Nick, xấu hổ về tôi :(. shoul d đã làm điều đó, thay vì gõ. Lấy làm tiếc!!. – Whoami

+0

Ah ha ha ha ha - chúng tôi đã làm tất cả! – Nick

Trả lời

11

Chỉ cần để câu trả lời là dễ dàng truy cập ở đây trên SO, ở đây nó là:

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.

Quoted from http://groups.google.com/group/android-ndk/browse_thread/thread/983c436239d48704?pli=1

+0

Phải làm gì nếu bạn sử dụng hệ thống xây dựng gradle mới với hỗ trợ ndk? – Roel

+0

@Roel Hệ thống xây dựng gradle mới thậm chí không sử dụng ** Application.mk **! –

3

Một cách khác là nếu bạn không có application.mk và android.mk tập tin,

thêm này trong build.gradle bạn

ndk{ 
    moduleName = your_module_name 
    stl = "c++_static" 
} 
Các vấn đề liên quan