2

I want to cross-compile a program which includes C and C++ both header file (ex. stdio.h and iostream) using arm-linux-androideabi-g++.

I use this command:

arm-linux-androideabi-g++ --sysroot=/home/user/android/android-ndk-r12b/platforms/android-18/arch-arm  -I /home/user/android/android-ndk-r12b/sources/cxx-stl/gnu-libstdc++/4.9/include -I /home/user/android/android-ndk-r12b/sources/cxx-stl/gnu-libstdc++/4.9/libs/armeabi-v7a/include -o demo1 demo.cpp

I get this error:

/tmp/ccnVY2tc.o:demo.cpp:function   __static_initialization_and_destruction_0(int, int): error: undefined reference to 'std::ios_base::Init::Init()'

/tmp/ccnVY2tc.o:demo.cpp:function __static_initialization_and_destruction_0(int, int): error: undefined reference to 'std::ios_base::Init::~Init()'

collect2: error: ld returned 1 exit status

How can I solve this problem?

jwpfox
  • 5,124
  • 11
  • 45
  • 42
Hiren
  • 75
  • 10
  • 3
    You need to link to c++ 's *libstdc++* (standard runtime library for c++) apparently. But let me ask, if you are on android why aren't you using the android studio horrible things that JUST WORK? Also, just to use *iostream*? This would seem un unnecessary requirement to link against *libstdc++*. – Iharob Al Asimi Dec 20 '16 at 07:33
  • Do you have a file called `Applikation.mk` with the line `APP_STL:=stlport_static`in it? http://stackoverflow.com/questions/9130429/android-ndk-build-iostream-no-such-file-or-directory – Klas Lindbäck Dec 20 '16 at 07:35
  • @iharob Actually i want to make command line application first and for actual it is in big program which is use openCV library. it is successfully compiled on my host machine (ubuntu) but problem in cross-compiling. – Hiren Dec 20 '16 at 08:08
  • And i tried with -lstdc++ but same error. – Hiren Dec 20 '16 at 08:13
  • @Klas Lindbäck I dont have Application.mk. i am trying command line application – Hiren Dec 20 '16 at 08:25
  • Thanks for the replay. I am trying with Android.mk and Application.mk and use Opencv-android-sdk and i am able to cross-compile my code. – Hiren Dec 20 '16 at 12:41

0 Answers0