2012-03-15 21 views
7

Han instalado android-ndk-r7, e intentan compilar el archivo .cpp.No se puede incluir iostream en android por qué?

#include <iostream> 

using namespace std; 

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

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

} 

Ejecutado comando siguiente: metió en la carpeta JNI, y ejecutado

#ndk-build 

Got siguiente error:

/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 

¿Qué estoy haciendo mal?

archivo Mi Android.mk parece:

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

y Application.mk archivo se ve así:

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

amablemente señalar el error?

+0

@ Nick, que pena por mí :(. Shoul Lo he hecho, más bien escribiendo. ¡¡Lo siento!!. – Whoami

+0

¡Ah, ja, ja, ja, todos lo hemos hecho! – Nick

Respuesta

11

Sólo para que la respuesta sea fácilmente accesible aquí en SO, aquí está:

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.

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

+0

¿Qué hacer si usa el nuevo sistema de compilación gradle con soporte ndk? – Roel

+0

@Roel ¡El nuevo sistema de compilación gradle ni siquiera usa ** Application.mk **! –

3

Otra forma es que si usted no tiene application.mk y android.mk archivo,

poner esto en su build.gradle

ndk{ 
    moduleName = your_module_name 
    stl = "c++_static" 
} 
Cuestiones relacionadas