2011-08-25 82 views
3

我想在android中使用NDK构建一个C++代码。我直到我写我的方法,这里面的线这个错误意味着什么以及如何解决它?

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

我开始收到此错误,有一个参数vector < vector <float> > coordinates

一切都建立精细的方法

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 

我不知道为什么这正在发生,谷歌也没有帮助。

谢谢。

+0

索引0处是否有任何元素?看起来坐标是空的。 – taskinoor

+0

正如我所说的坐标是这个方法的参数,这是编译时错误而不是运行时。是的,在运行时坐标最终将至少有一个值 –

+0

你如何编译和链接你的代码?有没有可能你错过了标准库? – john

回答

0

当我改变

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

vector<float> firstPoint = coordinates[0]; 

它开始编译.....:S y时?

0

这看起来像一个链接器错误。您可能忘了将STL库引用添加到您的构建中。或者它不能被发现

0

你这样做了吗?

#include <stdexcept> 
#include <vector> 
using namespace std; 
1

这是一个链接错误。您需要将APP_STL := stlport_static添加到您的Apllication.mk文件中。另外请确保您使用-fno-exceptions标志,因为STLport不兼容C++异常和RTTI。

你可以从APPLICATION-MK.HTML得到更多的信息,这可以在NDK的docs文件夹中找到。 CPLUSPLUS-SUPPORT.HTML也值得一看。

+0

已经这样做 –

+0

请确保您使用'-fno-exceptions'标志。 STLport与C++异常和RTTI不兼容。 –

+0

看到我的答案。任何想法为什么这项工作? –

1

我想你在同一个项目中使用了两种不同的标准库实现。

它看起来像你正在编译你的文件(D的头文件)标准库的stlport实现在D:/ android ...,并且你链接到你的本地库。

你必须在你的ide(或Makefile)中配置链接器来使用相同实现的lib文件(D:/ android中的某处...我猜)。

相关问题