Eclipse CDT "Symbol NULL could not be resolved"

86,275

Solution 1

NULL is usually defined in stddef.h. This file is also usually included with stdlib.h and stdio.h.

And, you could always do this:

#ifndef NULL
#define NULL   ((void *) 0)
#endif

Solution 2

As Bob mentioned, i fix the bug just by rebuilt the index

  1. right your project
  2. choose "Index"
  3. choose "Rebuild"

Solution 3

I had the same problem: my makefile was running fine but I was getting errors like yours from the Eclipse CDT view.

I closed the current project, I opened a new "Makefile project with existing code" , specifying the right location source location of my project. After this, I checked that: right click project / C++ general / Paths and symbols / Gnu C++ / include directories is not empty and includes the correct paths of my project.

Then, I rebuilt the index (right click / index / rebuild).

Also, I use Eclipse CDT 7 and not Eclipse CDT 8 because CDT8 sometimes gives me compile errors from the GUI that I could not solve, eventhough the makefile was fine.

Solution 4

  • reason is :

NULL defined in stddef.h, but stddef.h is in xxx/include/linux not xxx/include

-> even though you have added MingW's xxx/include, still can not found NULL

  • the solution is:

add your MingW's include/linux path to your project

  • referer

(1) example of my xscale crosscompiler's include/linux path is: /opt/crosscompile/xscale/gcc-4.6.0-glibc-2.9/arm-xscale-linux-gnueabi/sysroot/usr/include/linux

added GNU C++ include linux path

(2) my post:Ubuntu Eclipse: Symbol ‘NULL’ could not be resolved

Solution 5

I think that you have not added header file that defines NULL . Add stdlib.h (#include statement). it defines NULL macros.

Share:
86,275
Admin
Author by

Admin

Updated on July 23, 2022

Comments

  • Admin
    Admin almost 2 years

    I just installed Eclipse CDT with MinGW. All the environment variables are set, includes, etc. Tried running a hello world and everything seems to be fine.

    I tried loading a C project that I had before in my computer, it seems to load everything fine, yet I get the following error with the NULL symbol :

    Symbol 'NULL' could not be resolved
    

    Any insights? Thanks!

  • Keith Thompson
    Keith Thompson over 12 years
    Actually I don't think the standard headers include each other; each of the several headers that defines NULL does so independently. And you could define it yourself, but there's no good reason to do so; just include the header.
  • Man Vs Code
    Man Vs Code over 12 years
    @Keith - Perhaps on some systems, but on Linux, stdlib.h includes stddef.h. And here's an example on Google Code Search - [google.com/codesearch#XAzRy8oK4zA/libc/include/…
  • Keith Thompson
    Keith Thompson over 12 years
    Ok, but the effect is as if it didn't include it. This: #include <stdlib.h> int main(void) { offsetof(struct { int i; }, i); return 0; } fails to compile.
  • Alex
    Alex almost 8 years
    Have you encounter a similar problem yourself?
  • Admin
    Admin almost 8 years
    yes , my problem is "symbol 'elf magic' could not be resolved"
  • Alex
    Alex almost 8 years
    Welcome to SO. Some tips about posting answers. Post an answer if: 1. you encountered a similar problem and was able to resolve it. 2. You think your answer can contribute (e.g. your solution is different, or the problem is slightly different but related to the original). Include more details in your answer.
  • Andrés Alcarraz
    Andrés Alcarraz almost 6 years
    this is not a solution to the problem it's just ignoring the symptom