我在Ubuntu 12.04 x64上,使用带有CDT插件的Eclipse Indigo,我的g ++版本是4.7.3。我-std=c++11
在发现选项中添加了编译器选项和相同的选项(即使在编写代码时代码没有自动完成)。
Eclipse用红色强调以下内容,并给出警告。但是,该程序在运行时(忽略错误)将打印预期结果(Compiled with gcc 4.7\n 1 0\n
)。如何解决此问题?
#include <unordered_set>
#include <iostream>
using namespace std;
int main()
{
unordered_set<int> s; // Symbol unordered_set cannot be resolved
cout << "Compiled with gcc " << __GNUC__ << '.' << __GNUC_MINOR__ << endl;
s.insert(0); // Method insert cannot be resolved
s.insert(1); // Method insert cannot be resolved
s.insert(0); // Method insert cannot be resolved
for(auto i = s.begin(); i != s.end(); ++i) cout << ' ' << (*i);
// Method begin and end cannot be resolved
cout << endl;
return 0;
}
这是Eclipse在命令行中调用的内容:
...$ gcc -E -P -v -dD -std=c++11 .../specs.c
Using built-in specs.
...
gcc version 4.7.3 (Ubuntu/Linaro 4.7.3-2ubuntu1~12.04)
在-std=c++11
为我的C
编译器关闭了编译器选项之后(因为无论如何都不需要它)-但是对于C++
编译器保持打开状态,输出到控制台的输出如下。
...$ g++ -E -P -v -dD -std=c++11 .../specs.cpp
Using built-in specs.
...
gcc version 4.7.3 (Ubuntu/Linaro 4.7.3-2ubuntu1~12.04)
而且,无论Eclipse显示给我什么错误,输出仍然是相同的,显示了无序集合的工作原理并已正确编译。显然,这只是构建之前的问题。如果我的索引器在构建之前无法正确解析,则该集合在运行时如何工作?
我放弃是因为我无能为力,清除了我的eclipse系统和我的~/.eclipse
文件夹,下载了Kepler及其CDT版本,现在一切正常。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句