Eclipse CDT 无法解析 std:array,std::vector 工作正常
Eclipse CDT cannot resolve std:array, std::vector works fine
我面临很多 说 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();
}
使用 C/C++ General -> Preposcessor Include Path, Macros etc. -> Porvides -> CDT GCC Built-in Compiler Settings
下的 -std=c++11
标志激活 c++11 功能,如 here or 所述。
我的问题没有重复,因为它适用于 std::vector
并且其他 c++11 功能得到正确处理。
header(#include <array>
)可以按F3解决
我正在使用 Eclipse CDT 版本:Neon.3 Release (4.6.3)。
问题是符号 __cplusplus
没有值 201103L。
要更改此设置,您需要
编辑 Project->Preferences->C/C++ General/C/C+ General->Paths and Symbols->GNU C++->Symbols
添加定义 __cplusplus
并将值设置为 201103L
setzen。
在Window->Preferences->C/C++/Build/Settings/Discovery/CDT GCC Build-in Compiler Settings
das 参数“-std=c++11”下添加命令行hinzufügen
在 Project->Preferences->C/C++ General/C/C++ General/Path and Symbols->Providers
下激活所有条目的复选框 Use global provider shared between projects
我的症状与 OP 报告的完全相同:
- 我之前应用了“-std=c++11”修复程序来使 "unique_ptr" 语法之类的现代 C++ 能够正常工作。
- std::vector 和其他 std 模板问题已无误地解决。
- 我有
#include <array>
并且 F3 成功导航到数组头文件。
我尝试了 schorsch312 提供的解决方案,它 有效 除了提供的步骤与我的 Eclipse 的 Neon 版本(OP 使用的相同版本)不完全一致。因此,我不得不稍微调整说明。这是对我有用的:
- Select 项目 -> 属性 -> C/C++ 常规 -> C/C++ 路径和符号 -> 符号
- 在该页面的语言下,select GNU C++
- 添加...
- 姓名:__cplusplus
- 值:201103L
- 检查:添加到所有配置
- 应用/确定。
Select Project -> C/C+ Index -> Rebuild -- 如果该操作没有自动触发。
现在,eclipse 可以正确解析对数组的引用。请注意,此解决方案假定您之前已经解决了使 c++11 语法正常工作的一般问题。
我面临很多 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();
}
使用 C/C++ General -> Preposcessor Include Path, Macros etc. -> Porvides -> CDT GCC Built-in Compiler Settings
下的 -std=c++11
标志激活 c++11 功能,如 here or
我的问题没有重复,因为它适用于 std::vector
并且其他 c++11 功能得到正确处理。
header(#include <array>
)可以按F3解决
我正在使用 Eclipse CDT 版本:Neon.3 Release (4.6.3)。
问题是符号 __cplusplus
没有值 201103L。
要更改此设置,您需要
编辑
Project->Preferences->C/C++ General/C/C+ General->Paths and Symbols->GNU C++->Symbols
添加定义__cplusplus
并将值设置为201103L
setzen。在
Window->Preferences->C/C++/Build/Settings/Discovery/CDT GCC Build-in Compiler Settings
das 参数“-std=c++11”下添加命令行hinzufügen在
Project->Preferences->C/C++ General/C/C++ General/Path and Symbols->Providers
下激活所有条目的复选框Use global provider shared between projects
我的症状与 OP 报告的完全相同:
- 我之前应用了“-std=c++11”修复程序来使 "unique_ptr" 语法之类的现代 C++ 能够正常工作。
- std::vector 和其他 std 模板问题已无误地解决。
- 我有
#include <array>
并且 F3 成功导航到数组头文件。
我尝试了 schorsch312 提供的解决方案,它 有效 除了提供的步骤与我的 Eclipse 的 Neon 版本(OP 使用的相同版本)不完全一致。因此,我不得不稍微调整说明。这是对我有用的:
- Select 项目 -> 属性 -> C/C++ 常规 -> C/C++ 路径和符号 -> 符号
- 在该页面的语言下,select GNU C++
- 添加...
- 姓名:__cplusplus
- 值:201103L
- 检查:添加到所有配置
- 应用/确定。
Select Project -> C/C+ Index -> Rebuild -- 如果该操作没有自动触发。
现在,eclipse 可以正确解析对数组的引用。请注意,此解决方案假定您之前已经解决了使 c++11 语法正常工作的一般问题。