简体   繁体   English

NetBeans 6.7.1,Linux,C ++中的“无法解决...”

[英]“Unable to resolve…” in NetBeans 6.7.1, Linux, C++

I am working with a small group on a C++ project in NetBeans. 我正在与NetBeans中的C ++项目的一个小组合作。

For some reason, NetBeans is reporting things like "string", "endl", "cout" as "Unable to Resolve" even though the correct libraries have been included. 出于某种原因,即使已包含正确的库,NetBeans也会将“string”,“endl”,“cout”等内容报告为“无法解析”。

The project compiles and runs as expected, so at the end of the day, it is no big deal, it is just that having everything marked as an error makes it quite annoying. 该项目按预期编译和运行,所以在一天结束时,这没什么大不了的,只是将所有标记为错误的内容都非常烦人。

I haven't been able to find anything on this bug. 我一直无法找到关于这个bug的任何内容。 Just one vague reference in a blog. 在博客中只是一个模糊的参考。 Has anyone else experienced it? 还有其他人经历过吗?

Obviously it isn't wide-spread, so there must be a setting/configuration that causes it. 显然它没有广泛传播,因此必须有一个设置/配置导致它。 Does anyone know who to prevent this from happening? 有谁知道谁阻止这种情况发生?

EDIT: 编辑:

No, these "errors" are solely in the IDE. 不,这些“错误”仅在IDE中。 The code compiles fine and runs. 代码编译好并运行。 The developer has used "using namespace std;" 开发人员使用了“using namespace std;” so there should be no issues. 所以应该没有问题。 It appears that the NetBeans IDE is buggy. 似乎NetBeans IDE存在问题。

Sample code: 示例代码:

#include <stdlib.h>
#include <string>
#include <iostream>

using namespace std;

int main(int argc, char** argv)
{
   string test;
   test = "Why?";

   cout << test << endl;

   return (EXIT_SUCCESS);
}

This code compiles and prints out "Why?" 这段代码编译并打印出“为什么?” but has "string", "cout" and "endl" marked as errors in the IDE. 但在IDE中将“string”,“cout”和“endl”标记为错误。 Explicitly using std:: makes no difference 明确使用std ::没有区别

Clean up Edit: 清理编辑:

For anyone interested, a few days later I had 6 updates available for NetBeans. 对于任何感兴趣的人,几天后我有5个可用于NetBeans的更新。 After installing this updates, the problem was rectified, despite the code not changing. 安装此更新后,问题得到纠正,尽管代码没有变化。 So, apparently it was a NetBeans bug. 所以,显然这是一个NetBeans错误。

hmm.. this same thing just happened to me. 嗯..同样的事情发生在我身上。 One time I started NetBeans up it just underlined all my calls to openGL (gl, glu and glut), and I couldn't get rid of the errors. 有一次我开始使用NetBeans,它只是强调了我对openGL(gl,glu和过剩)的所有调用,我无法摆脱错误。 It compiled just fine (+ I did not change anything in the code since the last time it showed no errors) 它编译得很好(+我在代码中没有更改任何内容,因为它上次显示没有错误)

After reading this post I checked for updates, updated and now it indicates no errors :) it's weird cuz I update regularly.. 阅读这篇文章后,我检查了更新,更新,现在它表明没有错误:)这是奇怪的因为我经常更新..

EDIT: nvm, now they are underlined again :( 编辑: nvm,现在再次加下划线:(

Try std::string , std::endl , std::cout , etc. 尝试std::stringstd::endlstd::cout等。

Or, 要么,

using std::string;
using std::endl;
using std::cout;

at the beginning of your source file, after you include the libraries. 在包含库之后,在源文件的开头。 Maybe your IDE is flagging them as errors but then using the standard namespace anyways. 也许您的IDE将它们标记为错误,但随后使用标准命名空间。

You can also just use 你也可以使用

using namespace std;

but that is generally a bad habit as it clutters the global namespace, and you can end up with ambiguities (the standard namespace is big). 但这通常是一个坏习惯,因为它会使全局命名空间变得混乱,并且最终会产生歧义(标准命名空间很大)。 Personally, I just put std:: before everything in my small projects, and a using std::______ in the project or blocks where I use it in larger ones. 就个人而言,我只是将std::放在我的小项目中的所有内容之前,并在项目中using std::______或者在较大的项目中使用它。

Anyways, that's what the error sounds like, but (at least in my experience) the program should fail to compile if this is the problem. 无论如何,这就是错误听起来的样子,但是(至少根据我的经验),如果这是问题,程序将无法编译。

Per your edit: 根据你的编辑:
if the errors you get are coming only from the IDE, maybe you have it in a wrong mode or something? 如果你得到的错误只来自IDE,也许你有错误的模式或什么? The code you posted in your example is simple enough C++ that any compiler or IDE which is willing to work with C++ would handle it no problem. 您在示例中发布的代码非常简单C ++,任何愿意使用C ++的编译器或IDE都可以处理它没问题。 If the errors you described came from your compiler, it would mean that you either didn't include the namespace or you were trying to compile C++ code with a C compiler -- maybe netbeans thinks you're writing C? 如果您描述的错误来自您的编译器,则意味着您要么没有包含命名空间,要么您尝试使用C编译器编译C ++代码 - 也许netbeans认为您正在编写C?

For anyone interested, a few days later I had 6 updates available for NetBeans. 对于任何感兴趣的人,几天后我有5个可用于NetBeans的更新。 After installing this updates, the problem was rectified, despite the code not changing. 安装此更新后,问题得到纠正,尽管代码没有变化。 So, apparently it was a NetBeans bug. 所以,显然这是一个NetBeans错误。

FWIW I had the same issue with Netbeans 6.8 on Ubuntu 10.04. FWIW我在Ubuntu 10.04上遇到与Netbeans 6.8相同的问题。 Frustratingly Netbeans told me also that it was up to date in the Help --> Check for updates menu (as this is the current version for Ubuntu). 令人沮丧的Netbeans也告诉我,它在帮助 - >检查更新菜单中是最新的(因为这是Ubuntu的当前版本)。

Removing Netbeans via synaptic/aptitude and manually downloading and installing the latest version (6.9.1) also resolved the issue for me. 通过synaptic / aptitude删除Netbeans并手动下载和安装最新版本(6.9.1)也解决了我的问题。 I'm hoping there aren't more such nasties in store... 我希望商店里没有更多这样的恶作剧......

Now that I've resolved this and applied this performance patch, I've got a really sweet IDE set up with fast code completion. 现在我已经解决了这个并应用了这个性能补丁,我已经设置了一个非常好的IDE,快速完成代码。 It's a shame this experience isn't available out of the box, I spent a fair bit of time on both Eclipse CDT and Netbeans trying to get things working well. 很遗憾这种体验不是开箱即用的,我花了相当多的时间在Eclipse CDT和Netbeans上试图让事情顺利进行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM