【问题标题】:Eclipse editor will not recognize C++ template types, when using Android NDK使用 Android NDK 时,Eclipse 编辑器将无法识别 C++ 模板类型
【发布时间】: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].xint 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


    【解决方案1】:

    可能是this 可以帮助您,您必须在项目属性中包含正确的 STL 标头。

    【讨论】:

    • 我已经完成了所有这些; std 类型需要这些才能被识别(例如向量)。但这里的问题是编辑器中无法识别模板“返回类型”。请注意,Eclipse 并没有说“向量”无法识别。而是说无法解析“x”(仅在使用特定语法时)。
    猜你喜欢
    • 2020-11-13
    • 1970-01-01
    • 1970-01-01
    • 2012-09-08
    • 1970-01-01
    • 1970-01-01
    • 2015-01-17
    • 2012-07-09
    • 1970-01-01
    相关资源
    最近更新 更多