Erroneous "Unable to resolve identifier" in Netbeans

16,047

Solution 1

I know this question is seven months old but since it came up as the second result to a google search I'll tell the answer I came up with. For Netbeans at least. Go to your project properties and make sure you have you "C Compiler"->"C Standard" set to C11, and your "C++ compiler"->"C++ Standard" set to C++11. You have to set BOTH or it will still give false errors!

Solution 2

This will solve the problem:

  1. Right click on "Project".
  2. Select "Code Assistance".
  3. Clean C/C++ cache.
  4. Restart IDE.

Solution 3

Autocomplete and sometimes even syntax highlighting are always faulty with C++. The more you go in depth with C++ and C++11, the more Eclipse and Netbeans will start underlining everything with a red wavy line. Some of my (correct and perfectly compiling) programs are a huge red wavy line. I suggest you disable error markers altogether and you keep autocomplete, but in many cases it just won't work and you have to make the best of it.

Solution 4

I had the same situation. This was occurred because I used .c file instead of .cpp

Share:
16,047
Oebele
Author by

Oebele

Updated on June 11, 2022

Comments

  • Oebele
    Oebele almost 2 years

    My program compiles fine, but Netbeans tells me "Unable to resolve identifier to_string."

    I tried everything in "Netbeans 7.2 shows "Unable to resolve identifier" , although build is successful" and I set the "C++ standard" to "C++11" in the code assistance options.

    This is the only function giving this problem so far. It is however also the first C++11 feature I am using, which leads me to believe it has something to do with Netbeans not understanding that I am using C++11, although I specify it explicitly in the code assistance menu.

    Minimal example:

    #include <string>
    int main() {
        std::to_string(1);
    }
    

    EDIT: the same problem arises where using nullptr

    EDIT2: I suddenly realized it might be important to mention that I do not use a generated Makefile, but SCons.

  • Oebele
    Oebele about 8 years
    Just encountered the issue again with nullptr, tried your solution and it gives the correct highlighting now, so this seems to be the correct answer.
  • DarkTide
    DarkTide almost 8 years
    Disabling features that don't work is not exactlly a solution is it?, what's the point of using an IDE full of helpful features to end up disabling, you should recommend then using a text editor instead of an IDE.
  • DarkTide
    DarkTide almost 8 years
    Don't know how you found this but you saved me from going nuts :)
  • LuissRicardo
    LuissRicardo over 7 years
    @Oebele This fixed my issue. I had TWO (!) different projects in Netbeans. In one I had both C++ compiler and C Compiler with C++11 and C11 respectively. In the other project I had both of them to the default. But I had the issue in the later (with the default compilers). When I changed the compilers for the first project, it immediately fixed my issue. Thanks.
  • Eaton Emmerich
    Eaton Emmerich almost 7 years
    I agree it isn't a solution. But it is an answer because the reality is: Netbeans IDE just can't cope with all these complex abstractions. If this is not what you want, A different IDE/Application than Netbeans would be better suited. (I don't really know any much better ones though)
  • Rebirth
    Rebirth over 5 years
    This issue still exists in 8.2 on both Linux and Windows, even though the default (under Tools) is set up correctly. It's a little annoying that this has to be setup per project, but it seems to work even with c14 (not tried c17).
  • Peter
    Peter about 5 years
    Yep. Still the same in NB 10. Wasted hours on that until I found this thread.
  • Joe Dimig
    Joe Dimig about 4 years
    This worked for me! I tried setting the compilers for C and C++ to v11, but it didn't work even after restarting Netbeans. But clearing the cache worked wonderfully!
  • Chris Holt
    Chris Holt about 4 years
    Another wrinkle to add to this solution: most of the files in my project had a C++ level set on the individually. I have no idea why, as I'm the only project user and I never did it. The solution was to open the xml project file and find all instances of the attribute "flavor2" on all the <item> nodes and set them all to "0". a quick regex search and replace, save and ta-da, problem fixed.