30

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!

The Student
  • 27,520
  • 68
  • 161
  • 264
Alex
  • 363
  • 1
  • 4
  • 6

13 Answers13

42

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
Man Vs Code
  • 1,058
  • 10
  • 14
  • 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. – Keith Thompson Sep 15 '11 at 18:47
  • 1
    @Keith - Perhaps on some systems, but on Linux, stdlib.h includes stddef.h. And here's an example on Google Code Search - [http://google.com/codesearch#XAzRy8oK4zA/libc/include/stdlib.h&q=stdlib.h&type=cs] – Man Vs Code Sep 16 '11 at 04:35
  • Ok, but the effect is as if it didn't include it. This: `#include int main(void) { offsetof(struct { int i; }, i); return 0; }` fails to compile. – Keith Thompson Sep 16 '11 at 08:37
  • this is not a solution to the problem it's just ignoring the symptom – Andrés Alcarraz May 26 '18 at 11:10
24

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

  1. right your project
  2. choose "Index"
  3. choose "Rebuild"
Veger
  • 37,240
  • 11
  • 105
  • 116
hukeping
  • 665
  • 7
  • 12
5

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.

Bob Yoplait
  • 2,421
  • 1
  • 23
  • 35
2
  • 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

crifan
  • 12,947
  • 1
  • 71
  • 56
1

I just fixed an error like this and thought as no one else had found this solution I'd post it. I found that the stdlib had declared NULL as ___need_NULL in my AVR GCC compiler. This caused an error in Eclipse IDE. The error was however caused by Coden Analysis not finding the anomaly and so winging that the symbol could not be found. You can turn Coden off in Preferences under "General -> Startup/Shutdown" or change its behaviour in C/C++ Code analysis.

This may explain the sometimes random nature others are experiencing

richendes
  • 31
  • 3
1

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

BrettWatts
  • 87
  • 9
0

I was looking for answers here about this because I found out that CDT sometimes fails resolving the headers of the standard library. I still don't know why and how to reproduce the bug. Just restart CDT and all is solved.

Adrián Pérez
  • 2,186
  • 4
  • 21
  • 33
0

I was having the same error and I fixed it by right clicking on your project, hover over the index tab and click Rebuild. My errors went away after that.

Cwells
  • 13
  • 3
0

Just add C:\MinWG\lib to the Eclipse's Library Paths.

The Student
  • 27,520
  • 68
  • 161
  • 264
0

I also encounter a similar problem which is "Symbol elf magic could not be resolved", and the elf header has already been included. I think that the problem may be caused by library cache,for restarting software can solve the problem. Thank for others' help.

  • Have you encounter a similar problem yourself? – Alex Jun 29 '16 at 11:34
  • yes , my problem is "symbol 'elf magic' could not be resolved" – user6528152 Jun 29 '16 at 11:44
  • 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. – Alex Jun 29 '16 at 11:48
0

nothing of the suggestions above helped me. Every time opening a file the exclipse reports dozens of errors.

What helped in the end: Closing all files, then deleting the bugs manually (right click on the error list in the Problems window), then do a rebuild index.

humfry
  • 1
0

This problem is still coming up in 2019... there are many different causes/solutions.

I was getting unresolved symbols in the editor for NULL and everything in stdio.h (stderr, printf etc.) but compile worked fine. Nothing helped until I went in project properties and deleted a bunch of unnecessary C/C++ include paths. After that reindexing fixed the problem.

In another case I had an undefined symbol for a class name that was involved in some conditional preprocessor macro trickery. Adding the header file which defines the macro to "Index all variants of specific headers" in C/C++ indexer options (after checking "Enable project specific settings) fixed it.

This shows the the eclipse CDT indexer can get confused easily.

Georgie
  • 2,448
  • 2
  • 17
  • 13
0

Set ${COMMAND} to gcc on Linux

Under "Preprocessor Include Paths, Macros, etc." and "CDT GCC Built-in Compiler Settings" there is an undefined ${COMMAND} variable if you imported the sources from an existing Makefile project.

Eclipse tries to run that command to parse its stdout to find headers, but ${COMMAND} is not set by default, and so it is not able to do so.

I have explained this in more detail at: "Unresolved inclusion" error with Eclipse CDT for C standard library headers

Ciro Santilli OurBigBook.com
  • 347,512
  • 102
  • 1,199
  • 985