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

12

63

I'm using the Netbeans IDE 7.2 with 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 ...)

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

Minutes answered 16/2, 2013 at 17:48 Comment(4)
Where do you get the idea that 'everything is fine' if you get linker errors? Nitpicking aside, those errors almost certainly result from you not including the relevant libraries into the build process.Photoreconnaissance
The build was successful (build log), only the IDE show me errors.Minutes
Can you post the build log and maybe a screenshot of the errors ?Scottie
This question lacks important details. Are you asking for a general solution for when "There are errors, but everything is fine"?Canzona
S
110

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

Unresolved Identifier

If the source of the .cpp file looks like this

enter image description here

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

enter image description here

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

enter image description here

Set the include path correct.

I hope that can help you.

Sinhalese answered 16/2, 2013 at 20:11 Comment(8)
What did you use to highlight the menu items in the screenshots?Sandfly
@h3nr1x : What do you mean?Sinhalese
What software did you use to draw the green border rounded rectangle around the highlighted items in the image above?Sandfly
@h3nr1x : Ulead Photoimpact 8 to 12 . It's now Corel .Sinhalese
Reparse project does not show up in netbean 12. Any idea?Aholah
@Aholah : sorry at the moment I don't use Netbeans 12. Maybe Next Year :-)Sinhalese
Thanks @moskito-x. I got the solution. Right click on "Project". Select "Code Assistance". Clean C/C++ cache. Restart IDE.Aholah
Welcome. Pl see my ans below.Aholah
M
10

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.

Maryland answered 14/4, 2014 at 21:47 Comment(2)
For me the setting was under the drop-down list labelled C++ Standard, I assume that's effectively the same as manually adding it to additional options. My non-netbeans Makefiles have -std=gnu++0x, so that would probably work too, but it would have to go in the additional options, since it's not in the drop-down list.Dorcas
I had the same problem on my Netbeans 8.2. The first time this problem disappeared after changing the "C++ Standard" option to "C++11". When I've ran Netbeans another day, I saw this issue again. Then I've changed "C++ Standard" to <Default> and the problem disappeared (again).Telecommunication
W
9

TL;DR

UTF-8 WITH BOM can cause problems too.

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:

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 .cpp file 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 convert it.

  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.

Waldo answered 22/9, 2013 at 12:54 Comment(2)
All this is great, thanks !! can I change the encoding without having to follow this process for each file? i.e. can I change the encoding directly in NetBeans?Pardoes
@mm_: You're welcome! Maybe you could try this: https://mcmap.net/q/211245/-how-to-change-file-encoding-in-netbeans. Haven't tested it though, but I'm curious whether it works correctly for a file which has the encoding UTF-8 with BOM (or any other encoding except UTF-8 without BOM).Waldo
T
3

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

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

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

Tola answered 7/4, 2017 at 13:22 Comment(0)
A
1

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.

Anyaanyah answered 30/5, 2017 at 23:44 Comment(0)
D
0

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::vector etc) and the answers here didn't seem to help.

Dorcas answered 13/5, 2014 at 12:26 Comment(0)
T
0

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.

Structure in profile.h file was:

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.

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

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)

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:

/usr/bin/find /Users/USER_NAME/ -mmin -2 –ls
Traynor answered 5/8, 2016 at 19:33 Comment(0)
Y
0

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

Yellowknife answered 17/8, 2016 at 20:47 Comment(0)
A
0

Three ways to solve the issue of "unable to resolve identifier" error in Netbeans 12.

  1. Right click on "Project". Select "Code Assistance". Clean C/C++ cache. Restart IDE.
  2. Right click "Project properties"---> go to build--> under C/c++ compiler, set both your C and C++ compiler to the same standard, on every C/C++ project.
  3. Under tools--> options--> C/C++-->code assistance, change:__cplusplus=199711L to:__cplusplus=201402L for C++14 or to __cplusplus=201103L for C++11

I realised while resolving my own problem, the proper/aligned enclosing braces could cause the above error. Make sure your braces are balanced and aligned.

Aholah answered 5/10, 2020 at 15:29 Comment(1)
sure. see hereAholah
D
0

I had the same problem after copying a code having NULL comparison:

while (str1[i] != ’\0’) {
out[i] = str1[i];
i++;}

After searching a lot , it turned out the weird quotation used is the problem , I changed it to the normal ' and everything worked normal

while (str1[i] != '\0') {
out[i] = str1[i];
i++;}
Dissatisfactory answered 26/2, 2021 at 5:31 Comment(0)
A
-2

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

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

Aras answered 13/5, 2015 at 9:17 Comment(0)
K
-3

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

Kay answered 23/12, 2014 at 9:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.