3

I am trying to build a C++ code using NDK in android. I have a method which has a parameter vector < vector <float> > coordinates

Everything builds fine until I write this line inside my method

vector<float> firstPoint = coordinates.at(0);

I start getting this error

D:/eclipseworkspace/myLibProject/obj/local/armeabi/libmyLibProject.a(FileName.o): In function `std::priv::_Vector_base<std::vector<float, std::allocator<float> >, std::allocator<std::vector<float, std::allocator<float> > > >::_M_throw_out_of_range() const':
D:/androidndk/sources/cxx-stl/stlport/stlport/stl/_vector.c:45: undefined reference to `std::__stl_throw_out_of_range(char const*)'
collect2: ld returned 1 exit status
make: *** [/cygdrive/d/eclipseworkspace/myLibProject/obj/local/armeabi/libOutputName.so] Error 1

I have no clue why this is happening and Google is not helping either.

Thanks.

john
  • 85,011
  • 4
  • 57
  • 81
Haris Hasan
  • 29,856
  • 10
  • 92
  • 122
  • Is there any element at index 0? Looks like coordinates is empty. – taskinoor Aug 25 '11 at 06:13
  • As I said coordinate is parameter to this method and this is compile time error not runtime. And yes at runtime coordinates will eventually have at least one value – Haris Hasan Aug 25 '11 at 06:14
  • How are you compiling and linking your code? Is it possible you are missing the standard libraries? – john Aug 25 '11 at 06:19
  • If compiler is unable to find libs then Why the error comes when I try to access value and not when I have declared it in the method parameters? – Haris Hasan Aug 25 '11 at 06:47
  • Because **most** of the implementation of vector is in header files, and so doesn't need a library. It seems in your case everything is in header files except the exception class thrown by vector::at. This seems perfectly normal. (One confusing aspect of STLPort is that you see a reference to _vector.c, but if you check the STLPort code you'll see that _vector.c is included in the vector header file). – john Aug 25 '11 at 07:07

5 Answers5

1

This is a linking error. You need to add APP_STL := stlport_static to your Apllication.mk file. Also make sure that you use -fno-exceptions flag, since STLport is not compatible with C++ exceptions and RTTI.

You can get more info in APPLICATION-MK.HTML which is availavle in the docs folder of the NDK. CPLUSPLUS-SUPPORT.HTML is also worth to read.

Kirill V. Lyadvinsky
  • 97,037
  • 24
  • 136
  • 212
1

I think you are using two different implementation of the standard library in the same project.

It looks like you are compiling your files with (the headers of) an stlport implementation of the standard library in D:/android..., and you link against your local library.

You have to configure the linker in your ide (or Makefile) to use also the lib file of the same implementation (somewhere in D:/android... I guess).

Nicolas Grebille
  • 1,332
  • 8
  • 15
0

this looks like a linker error. You probably forgot to add STL library reference to your build. Or it can't be found

Oleg
  • 798
  • 3
  • 7
0

Did you do this ?

#include <stdexcept>
#include <vector>
using namespace std;
Ajeet Ganga
  • 8,353
  • 10
  • 56
  • 79
0

When I changed

vector<float> firstPoint = coordinates.at(0);

to

vector<float> firstPoint = coordinates[0];

it started compiling..... :s y?

Haris Hasan
  • 29,856
  • 10
  • 92
  • 122