【发布时间】:2014-04-15 08:42:30
【问题描述】:
我正在尝试使用 NDK 和 Eclipse CDT 将以下简单的 C++ 代码编译为原生 Android 代码:
#include <vector>
using namespace std;
class Pt {
public:
Pt(int _x, int _y);
int x;
int y;
};
Pt::Pt(int _x, int _y){
x = _x;
y = _y;
}
void test(){
std::vector<Pt> pts;
pts.push_back(Pt(2,3));
int i = pts[0].x; //error here
}
我可以从命令行使用ndk-build.cmd 毫无问题地编译代码,甚至可以从Eclipse 中编译它。问题是在最后一行(这里有 //error here 注释的地方),Eclipse 编辑器报告了以下错误:
Field 'x' could not be resolved
可能的解决方案是:
- 像这样写
pts[0].x:int i = ((Pt)pts[0]).x; - 使用 var:
Pt apt = pts[0]; int i = apt.x;(令人惊讶的是,这行得通)
我花了将近 2 天的时间尝试使用自定义路径设置 eclipse 以包含文件、使用索引器、升级到最新的 NDK 以及我能想象到的一切。问题依然存在。这个问题显然出现在每个采用参数化类型的类中(不仅是向量)。 虽然 Eclipse 确实会编译代码,但报告此错误的事实会导致 Android 项目被标记为“有错误”,因此无法将其作为一个整体运行。
非常感谢任何帮助, 谢谢
【问题讨论】:
标签: android c++ eclipse android-ndk eclipse-cdt