【问题标题】:Eclipse CDT cannot resolve std:array, std::vector works fineEclipse CDT 无法解析 std:array,std::vector 工作正常
【发布时间】:2018-03-24 02:44:09
【问题描述】:

我面对很多 Symbol 'array' could not be resolved,代码构建良好。

#include <math.h>
#include <array>
#include <sstream>
#include <string>

static std::string printArray(std::array<double, 3> data) {
  std::ostringstream strs;
  strs << "( " << data[0] << " " << data[1] << " " << data[2] << " )";
  return strs.str();
}

static std::string printVector(std::vector<double> data) {
  std::ostringstream strs;
  strs << "( " ;
  for (const auto & value : data )
      strs << value << " ";
  strs << " )";
  return strs.str();
}

herehere 所述,使用C/C++ General -&gt; Preposcessor Include Path, Macros etc. -&gt; Porvides -&gt; CDT GCC Built-in Compiler Settings 下的-std=c++11 标志激活c++11 功能。

我的问题没有重复,因为它适用于std::vector,并且其他 c++11 功能得到了正确处理。

按 F3 可以解析标题 (#include &lt;array&gt;)。

我正在使用 Eclipse 的 CDT 版本:Neon.3 Release (4.6.3)。

【问题讨论】:

  • 在构建过程中我没有收到任何错误。我正在使用基于 Makefile 的构建。
  • @VT,我认为这不是重复的。我做了那里建议的步骤。他们为std::vector 工作,但不为std::array 工作。
  • accepted answer 在您链接到用于设置 -std=c++11 标志的问题中,它没有提到“Preposcessor[sic] Include Path, Macros etc.”
  • 你试过重建索引吗?
  • @Someprogrammerdude:设置的位置从我正在使用的 neo3 的答案中使用的 Eclipse Indigo 20110615-0604 版本更改。

标签: c++ eclipse c++11 eclipse-cdt stdarray


【解决方案1】:

我的症状与 OP 报告的完全相同:

  • 我之前应用了“-std=c++11”修复来使现代 C++ 事物(如“unique_ptr”语法)正常工作。
  • std::vector 和其他 std 模板的东西都解决了,没有错误。
  • 我有#include &lt;array&gt;,F3 成功导航到数组头文件。

我尝试了 schorsch312 提供的解决方案,它工作,除了所提供的步骤与我的 Neon 版本的 Eclipse 不完全一致(OP 使用的版本相同)。因此,我不得不稍微调整说明。这对我有用:

  1. 选择项目 -> 属性 -> C/C++ 常规 -> C/C++ 路径和符号 -> 符号
  2. 在该页面的 Languages 下,选择 GNU C++
  3. 添加...
    • 名称:__cplusplus
    • 值:201103L
  4. 检查:添加到所有配置
  5. 应用/确定。

选择项目 -> C/C+ 索引 -> 重建 -- 如果该操作没有自动触发。

现在,eclipse 可以正确解析对数组的引用。请注意,此解决方案假定您之前已经解决了使 c++11 语法正常工作的一般问题。

【讨论】:

    【解决方案2】:

    问题是符号__cplusplus 没有值201103L。

    要改变这个,你需要

    • 编辑Project-&gt;Preferences-&gt;C/C++ General/C/C+ General-&gt;Paths and Symbols-&gt;GNU C++-&gt;Symbols 添加定义__cplusplus 并将值设置为201103L setzen。

    • Window-&gt;Preferences-&gt;C/C++/Build/Settings/Discovery/CDT GCC Build-in Compiler Settings das Argument "-std=c++11" der 命令行 hinzufügen 下添加

    • Project-&gt;Preferences-&gt;C/C++ General/C/C++ General/Path and Symbols-&gt;Providers 下为所有条目激活复选框Use global provider shared between projects

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-09-15
      • 1970-01-01
      • 1970-01-01
      • 2013-09-19
      • 2015-11-07
      • 2012-02-16
      • 1970-01-01
      相关资源
      最近更新 更多