Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to include iostream in android why?

Tags:

c++

android

Have installed android-ndk-r7, and trying to compile .cpp file.

#include <iostream>

using namespace std;

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

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

} 

Executed following command: Got into jni folder, and executed

#ndk-build

Got following 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

What am i doing wrong ?

My Android.mk file looks like:

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

and Application.mk file looks like:

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

Kindly point out the mistake?

like image 883
Whoami Avatar asked Mar 15 '12 14:03

Whoami


People also ask

What can I use instead of iostream?

You can use <cstdio> instead of <iostream> , if you just need to output text. To print a string without formatting, you can use puts . Use printf to print with format and conversion specifiers.

Why do we need #include iostream?

So, #include is a preprocessor directive that tells the preprocessor to include header files in the program. < > indicate the start and end of the file name to be included. iostream is a header file that contains functions for input/output operations ( cin and cout ).

Do I need to include iostream?

iostream is used to handle input and output. If you don't need either of those, you don't need to include it. But it's really rare to not include for a console application.


1 Answers

Just so the answer is readily accessible here on SO, here it is:

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

like image 164
Fred Larson Avatar answered Oct 17 '22 01:10

Fred Larson