Linux Netbeans 7.2 显示“无法解析标识符”,尽管构建成功

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14913243/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 19:02:37  来源:igfitidea点击:

Netbeans 7.2 shows "Unable to resolve identifier" , although build is successful

c++linuxnetbeansnetbeans-7

提问by leon22

I'm using the Netbeans IDE 7.2with C/C++ plugin(last version 1.18.1.1) and if I build my project everything is fine but the IDE show me errors (e.g. unable to resolve identifier ...)

我正在使用带有C/C++ 插件(最新版本 1.18.1.1)的Netbeans IDE 7.2,如果我构建我的项目一切正常,但 IDE 会显示错误(例如无法解析标识符......)

Anyone else have this bug and how can I solve it?

其他人有这个错误,我该如何解决?

采纳答案by moskito-x

Here's an excerpt from my answer to another question.

这是我对另一个问题的回答的摘录。

Unresolved Identifier

未解析的标识符

If the source of the .cpp file looks like this

如果 .cpp 文件的来源看起来像这样

enter image description here

在此处输入图片说明

Click with the right mouse button on your project.
Check C/C++ Code As...
Run Reparse Project.

用鼠标右键单击您的项目。
检查C/C++ Code As...
运行 Reparse Project.

enter image description here

在此处输入图片说明

If that is not enough.
Go to Project Properties
Fill in the Includeinput field as described.

如果这还不够。
转到按照说明Project Properties
填写Include输入字段。

enter image description here

在此处输入图片说明

Set the include path correct.

设置正确的包含路径。

I hope that can help you.

我希望这可以帮助你。

回答by Sk8erPeter

TL;DR

TL; 博士

UTF-8 WITHBOM can cause problems too.

UTF-8 WITHBOM 也会导致问题。

PROBLEM

问题

I just had the same problem, and I tried lots of possible solutions, but none of them worked, until I found out the source of the problem, which was a bit funny. I know this question has already been answered, but I write down my solution, maybe it will solve the problem of someone else suffering from the same problem.

我只是遇到了同样的问题,我尝试了很多可能的解决方案,但都没有奏效,直到我找到了问题的根源,这有点好笑。我知道这个问题已经有人回答了,但是我写下我的解决方案,也许它会解决其他人遇到同样问题的问题。

For example, I got "Unable to resolve identifier Vector"when defining struct Vector, while it was correct:

例如,我在定义时得到“无法解析标识符向量”struct Vector,但它是正确的:

Unable to resolve identifier Vector

无法解析标识符向量

I got many errors similar to this when declaring/defining functions, etc. Additionally, my code assistance didn't work because of the amount of errors.

在声明/定义函数等时,我遇到了许多与此类似的错误。此外,由于错误的数量,我的代码帮助不起作用。

SOLUTION

解决方案

  1. I opened the .cppfile in Notepad++, and saw the file was encoded in regular UTF-8, which means that the file begins with the byte order mark (BOM)character:

    Notepad++ - file encoded in UTF-8 WITH BOM

  2. So I clicked EncodingConvert to UTF-8 without BOM:

    Notepad++: Encoding - Convert to UTF-8 without BOM

    Note:do NOT just switch to "Encode in UTF-8 without BOM", because it can mess up some special characters (e.g. characters containing accents, etc.). So convertit.

  3. Save

  4. Problem gone: no errors reported in NetBeans anymore:

    NetBeans - no errors reported anymore, problem solved

    I hope it saves some time for someone else too.

  1. .cppNotepad++ 中打开文件,看到文件是用常规UTF-8编码的,这意味着文件以字节顺序标记 (BOM)字符开头

    Notepad++ - 以 UTF-8 编码的文件和 BOM

  2. 所以我点击了EncodingConvert to UTF-8 without BOM

    Notepad++:编码 - 转换为 UTF-8 而不使用 BOM

    注意:不要只是切换到"Encode in UTF-8 without BOM",因为它可能会弄乱一些特殊字符(例如包含重音的字符等)。所以转换它。

  3. 节省

  4. 问题消失了:NetBeans 中不再报告错误:

    NetBeans - 不再报告错误,问题已解决

    我希望它也为其他人节省一些时间。

回答by Rafa

i had the same problem, but i recognized it appears after i changed properties-> c++ compiler -> Compilation Line -> additional options to -std=c++11. if change the settings to default the error "unable to resolve identifier" disapears.

我有同样的问题,但我意识到它在我更改属性-> c++ 编译器-> 编译行-> -std=c++11 的附加选项后出现。如果将设置更改为默认值,错误“无法解析标识符”就会消失。

回答by craq

We develop our code on one computer and compile on another. I was getting these distracting markups until I "set Build Host" to the remote machine (in the right-click menu for the project).

我们在一台计算机上开发我们的代码并在另一台计算机上编译。在我将构建主机“设置为远程机器”(在项目的右键单击菜单中)之前,我一直在使用这些令人分心的标记。

I'm still not sure what the problem on the development computer was, since the unresolved identifiers were things from the standard library (size_t, std::vectoretc) and the answers here didn't seem to help.

我仍然不知道在开发计算机上的问题是,由于未解决的标识符是从标准库(的东西size_tstd::vector等),这里的答案似乎并没有帮助。

回答by Yury

try Click by Right button the file, Properties->General->Exclude from code assistance (disable)

尝试按右键单击文件,属性->常规->从代码帮助中排除(禁用)

回答by Tushar Goswami

Mine worked once i renamed my main.c to main.cpp.

我的工作一旦我将我的 main.c 重命名为 main.cpp。

Based on the file extension, the behavior of Netbeans Code Assistance changes

基于文件扩展名,Netbeans Code Assistance 的行为发生变化

回答by EmbeddedGuy

I often have this error, and as others mentioned, usually I add space character, save the file, remove the space character... and all identifiers are solved.

我经常有这个错误,正如其他人提到的,通常我添加空格字符,保存文件,删除空格字符......所有标识符都解决了。

This time it did not work. My project, which I compiled thousand times, and it always worked, suddenly crashed MPLAB X IDE v3.35 (Mac OSX, but likely it doesn't matter), while typing text. After this I have in one file only and for one structure only, all identifiers unresolved.

这一次没有奏效。我的项目,我编译了数千次,并且一直有效,但在输入文本时突然崩溃了 MPLAB X IDE v3.35(Mac OSX,但可能无关紧要)。在此之后,我只有一个文件,只有一个结构,所有标识符都未解析。

Structure in profile.h file was:

profile.h 文件中的结构是:

typedef struct
{
    int state;                      ///< state machine current state
    int enabled;                    ///< machine can be ENABLED or DISABLED
    int flag;                       ///< to initiate profile execution
   ... many variables here ...
    unsigned long timestamp;        ///< variable used for local timing
} profile_struct;

In my profile.c file any variables from this structure became unresolved, but project compiled and worked fine.

在我的 profile.c 文件中,此结构中的任何变量都无法解析,但项目已编译并运行良好。

After a frustrating hour of trying, this solved my problem: Erased the whole MPLABX cache directory.

经过令人沮丧的一小时尝试,这解决了我的问题:擦除了整个 MPLABX 缓存目录。

In my case, it is located at:

就我而言,它位于:

/Users/USER_NAME/Library/Caches/mplab_ide/dev/v3.35/var

(need to erase the whole 'var' directory; and of course replace the USER_NAME with your user name)

(需要删除整个 'var' 目录;当然用您的用户名替换 USER_NAME)

Note, that the 'Library' is a hidden directory, but you can still access it if you enable viewing hidden files, or go straight to it via terminal.

请注意,“库”是一个隐藏目录,但如果您启用查看隐藏文件或通过终端直接访问它,您仍然可以访问它。

Lastly, on your computer it might be somewhere else. I found mine by watching, which files were modified on my computer in the last 2 minutes, by using the terminal command:

最后,在您的计算机上,它可能位于其他地方。通过使用终端命令,我通过观察在过去 2 分钟内在我的计算机上修改了哪些文件找到了我的:

/usr/bin/find /Users/USER_NAME/ -mmin -2 –ls

回答by Stuart

I always have to reinstall MPLAB X when this happens. Other things work from time to time, but that always works.

发生这种情况时,我总是必须重新安装 MPLAB X。其他事情不时奏效,但总是奏效。

回答by Ben Briggs

I recently had this error with netbeans 8.0.2 on OS X, and couldn't find an answer for what to do.

我最近在 OS X 上的 netbeans 8.0.2 上遇到了这个错误,并且找不到要做什么的答案。

I solved the problem by uninstalling the C/C++ plug-in, when I reopened netbeans it prompted me to 'fix code assistance..'.

我通过卸载 C/C++ 插件解决了这个问题,当我重新打开 netbeans 时,它提示我“修复代码帮助...”。

Clicking the prompt and letting it run the problem was fixed.

单击提示并让它运行问题已解决。

回答by nikals

I am using NetBeans 8.1 and the same problem popped up when I started a new C++ project. It solved itself after running the project through the debugger.

我使用的是 NetBeans 8.1,当我开始一个新的 C++ 项目时,同样的问题出现了。它通过调试器运行项目后自行解决。