Android ndk-build iostream: No such file or directory

Andrey Zavarin picture Andrey Zavarin · Feb 3, 2012 · Viewed 39.1k times · Source

I'm having problem with compiling cpp file using ndk-build tool (windows 7 with cygwin) Error appears when I try to compile cpp file with #include:

jni/native.cpp:5:20: error: iostream: No such file or directory

Here is my cpp file:

#include <jni.h>
#include <string.h>
#include <stdio.h>
#include <android/log.h>
#include <iostream>

#define DEBUG_TAG "NDK_SampleActivity"
#define  LOG_TAG    "hellojni"
#define  LOGI(...)  __android_log_print(ANDROID_LOG_INFO,LOG_TAG,__VA_ARGS__)
#define  LOGE(...)  __android_log_print(ANDROID_LOG_ERROR,LOG_TAG,__VA_ARGS__)


#ifdef __cplusplus
extern "C" {
#endif

void Java_com_test_ndk_SampleActivity_helloLog(JNIEnv* env, jobject thisobj, jstring logThis)
{
    jboolean isCopy;

    const char * szLogThis = env->GetStringUTFChars(logThis, &isCopy);

    __android_log_print(ANDROID_LOG_DEBUG, DEBUG_TAG, "NDK:LC: [%s]", szLogThis);

    env->ReleaseStringUTFChars(logThis, szLogThis);
}



#ifdef __cplusplus
}
#endif

And here is my Android.mk file:

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

APP_STL:=stlport_static 

LOCAL_LDLIBS := -llog

LOCAL_MODULE    := swingbyte-android

LOCAL_SRC_FILES := native.cpp

LOCAL_C_INCLUDES := $(LOCAL_PATH)/include-all
include $(BUILD_SHARED_LIBRARY)

I have iostream file in android ndk folder (NDK_ROOT\sources\cxx-stl\gnu-libstdc++\include) but I don't have any idea how to tell compiler to look for iotream (and other standart header files) in that folder.

It seems to that I'm missing one or few environment variables, or some comiler flags.

Answer

Gaetan picture Gaetan · Feb 3, 2012

I think "APP_STL:=stlport_static" must be in Application.mk file.

Create a "Application.mk" file and write "APP_STL:=stlport_static" in it.