2012-03-15 7 views
7

Hanno installato android-ndk-r7 e provato a compilare il file .cpp.Impossibile includere iostream in Android perché?

#include <iostream> 

using namespace std; 

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

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

} 

Eseguito seguente comando: Got nella cartella JNI, ed eseguito

#ndk-build 

Got seguente errore:

/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 

Che cosa sto facendo di sbagliato?

file di mio Android.mk assomiglia:

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

e Application.mk del file si presenta come:

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

di farmi notare l'errore?

+0

@ Nick, Vergogna su di me :(. Shoul Ho fatto questo, piuttosto digitando. Scusate!!. – Whoami

+0

Ah ah ah ah ah - l'abbiamo fatto tutti! – Nick

risposta

11

Basta quindi la risposta è facilmente accessibile qui su SO, qui è:

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.

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

+0

Cosa fare se si utilizza il nuovo sistema di sviluppo gradle con supporto ndk? – Roel

+0

@Roel Il nuovo sistema di sviluppo gradle non usa nemmeno ** Application.mk **! –

3

Un altro modo è che, se non si dispone di application.mk e android.mk di file,

aggiungere questo nella vostra build.gradle

ndk{ 
    moduleName = your_module_name 
    stl = "c++_static" 
} 
Problemi correlati