Cannot enable iostream in android, why?

Installed android-ndk-r7 and tried to compile the .cpp file.

#include <iostream> using namespace std; int main ( int argc, char ** argv) { cout <<"Hello World.."<<endl; } 

The following command is executed: I went into the jni folder and executed

 #ndk-build 

Received the 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 this:

 # 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 the Application.mk file looks like this:

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

Please indicate a mistake?

+7
source share
3 answers

It's just that the answer is easily available here on SO, here it is:

By default, the C ++ standard library is very minimal.

You need to set APP_STL in the Application.mk file.

I use:

APP_STL: = gnustl_static

but you could use a system, stlport_static, stlport_shared or gnustl_static.

It is documented in $ NDK / docs / CPLUSPLUS-SUPPORT.html and it is little hidden because the index file $ NDK / documentation.html does not list it.

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

+11
source

Another way is that if you don't have application.mk and android.mk file,

add this to your build.gradle

 ndk{ moduleName = your_module_name stl = "c++_static" } 
+3
source

I ran into this problem and spent several days updating my NDK from r10e to r20, several variables changed.

For NDK r10e

Android.mk:

 include $(CLEAR_VARS) LOCAL_MODULE := main LOCAL_SRC_FILES := ./main.cpp LOCAL_C_INCLUDES += $(LOCAL_PATH)/ LOCAL_CPP_EXTENSION := .cxx .cpp .cc LOCAL_CPPFLAGS := -fexceptions -frtti LOCAL_CPPFLAGS += -std=c++11 -D__cplusplus=201103L include $(BUILD_EXECUTABLE) 

Application.mk:

 APP_ABI := all APP_STL := gnustl_static NDK_TOOLCHAIN_VERSION := 4.9 APP_OPTIM := debug 

For NDK R20

Android.mk:

 include $(CLEAR_VARS) LOCAL_MODULE := main LOCAL_SRC_FILES := ./main.cpp LOCAL_C_INCLUDES += $(LOCAL_PATH)/ LOCAL_CPP_EXTENSION := .cxx .cpp .cc LOCAL_CPPFLAGS := -fexceptions -frtti LOCAL_CPPFLAGS += -std=c++11 -D__cplusplus=201103L -DANDROID_STL=c++_shared include $(BUILD_EXECUTABLE) 

Application.mk:

 APP_ABI := all #In general, you can only use a static variant of the C++ runtime if you have one and only one shared library in your application. APP_STL := c++_static NDK_TOOLCHAIN_VERSION := clang APP_PLATFORM := android-23 APP_OPTIM := debug 

and my main.cpp (including my bin_node.h):

 int main(int argc,char **argv) { printf("****************** tree node ******************\n"); amo::BinNode<int> root(0); amo::BinNode<int>* lchild1 = root.insertLeftChild(1); amo::BinNode<int>* rchild2 = root.insertRightChild(2); amo::BinNode<int>* lchild3 = lchild1->insertLeftChild(3); amo::BinNode<int>* rchild4 = lchild1->insertRightChild(4); amo::BinNode<int>* lchild5 = rchild2->insertLeftChild(5); amo::BinNode<int>* rchild6 = rchild2->insertRightChild(6); amo::BinNode<int>* lchild7 = lchild3->insertLeftChild(7); amo::BinNode<int>* rchild8 = lchild3->insertRightChild(8); amo::BinNode<int>* lchild9 = rchild6->insertLeftChild(9); amo::BinNode<int>* rchild10 = rchild6->insertRightChild(10); amo::BinNode<int>* lchild11 = rchild8->insertLeftChild(11); amo::BinNode<int>* rchild12 = rchild8->insertRightChild(12); printf("going to root.traversePre()\n"); root.traversePre(); printf("going to root.traversePreLoop()\n"); root.traversePreLoop(); printf("going to root.traversePreLoop2()\n"); root.traversePreLoop2(); printf("\n****************** main return ******************\n"); return 0;} 

Run ndk-build and build the executable

enter image description here

For more source code and information for this, check out my github

0
source

All Articles