C语言 Eclipse CDT“无法解析符号 NULL”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7433448/
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
Eclipse CDT "Symbol NULL could not be resolved"
提问by Alex
I just installed EclipseCDTwith MinGW.
All the environment variables are set, includes, etc. Tried running a hello world and everything seems to be fine.
我刚刚安装EclipseCDT了MinGW. 所有环境变量都已设置,包括等。尝试运行一个 hello world,一切似乎都很好。
I tried loading a Cproject that I had before in my computer, it seems to load everything fine, yet I get the following error with the NULLsymbol :
我尝试加载C我以前在计算机中拥有的项目,它似乎加载了所有内容,但出现以下NULL符号错误:
Symbol 'NULL' could not be resolved
Any insights? Thanks!
任何见解?谢谢!
回答by Man Vs Code
NULL is usually defined in stddef.h. This file is also usually included with stdlib.h and stdio.h.
NULL 通常在 stddef.h 中定义。该文件通常也包含在 stdlib.h 和 stdio.h 中。
And, you could always do this:
而且,你总是可以这样做:
#ifndef NULL
#define NULL ((void *) 0)
#endif
回答by hukeping
As Bob mentioned, i fix the bug just by rebuilt the index
正如鲍勃提到的,我只是通过重建索引来修复错误
- right your project
- choose "Index"
- choose "Rebuild"
- 正确你的项目
- 选择“索引”
- 选择“重建”
回答by Bob Yoplait
I had the same problem: my makefile was running fine but I was getting errors like yours from the Eclipse CDT view.
我遇到了同样的问题:我的 makefile 运行良好,但我从 Eclipse CDT 视图中收到了与您类似的错误。
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.
我关闭了当前项目,我打开了一个新的“Makefile project with existing code”,指定了我项目的正确位置源位置。在此之后,我检查了:右键单击项目 / C++ 常规 / 路径和符号 / Gnu C++ / 包含目录不为空,并且包含我项目的正确路径。
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.
此外,我使用 Eclipse CDT 7 而不是 Eclipse CDT 8,因为 CDT8 有时会给我来自 GUI 的编译错误,我无法解决,即使 makefile 很好。
回答by crifan
- reason is :
- 原因是:
NULL defined in stddef.h, but stddef.his in xxx/include/linuxnot xxx/include
NULL定义的stddef.h,但stddef.h在xxx/include/linux不xxx/include
-> even though you have added MingW's xxx/include, still can not found NULL
-> 即使你添加了 MingW 的xxx/include,仍然找不到NULL
- the solution is:
- 解决办法是:
add your MingW's include/linuxpath to your project
将您的 MingWinclude/linux路径添加到您的项目中
- referer
- 推荐人
(1) example of my xscale crosscompiler's include/linuxpath is: /opt/crosscompile/xscale/gcc-4.6.0-glibc-2.9/arm-xscale-linux-gnueabi/sysroot/usr/include/linux
(1) 我的 xscale 交叉编译器的include/linux路径示例是:/opt/crosscompile/xscale/gcc-4.6.0-glibc-2.9/arm-xscale-linux-gnueabi/sysroot/usr/include/linux


(2) my post:Ubuntu Eclipse: Symbol ‘NULL' could not be resolved
(2) 我的帖子:Ubuntu Eclipse: Symbol 'NULL' 无法解析
回答by richendes
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.
我刚刚修复了一个这样的错误,并认为没有其他人找到这个解决方案,我会发布它。我发现 stdlib 在我的 AVR GCC 编译器中将 NULL 声明为 ___need_NULL。这导致了 Eclipse IDE 中的错误。然而,错误是由 Coden Analysis 没有发现异常引起的,因此无法找到符号。您可以在“常规 -> 启动/关闭”下的首选项中关闭 Coden 或在 C/C++ 代码分析中更改其行为。
This may explain the sometimes random nature others are experiencing
这或许可以解释其他人有时会遇到的随机性
回答by BrettWatts
I think that you have not added header file that defines NULL. Add stdlib.h (#include statement). it defines NULL macros.
我认为您没有添加定义NULL 的头文件。添加 stdlib.h(#include 语句)。它定义了 NULL 宏。
回答by Tom Brito
Just add C:\MinWG\libto the Eclipse's Library Paths.
只需添加C:\MinWG\lib到 Eclipse 的库路径。
回答by user6528152
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.
我也遇到过类似的问题“符号精灵魔法无法解析”,精灵头已经包含了。我认为问题可能是库缓存引起的,重启软件可以解决问题。感谢他人的帮助。
回答by humfry
nothing of the suggestions above helped me. Every time opening a file the exclipse reports dozens of errors.
上面的建议都没有帮助我。每次打开文件时,exclipse 都会报告数十个错误。
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.
最后有什么帮助:关闭所有文件,然后手动删除错误(右键单击“问题”窗口中的错误列表),然后重建索引。
回答by Georgie
This problem is still coming up in 2019... there are many different causes/solutions.
这个问题在 2019 年仍然出现......有许多不同的原因/解决方案。
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.
我在编辑器中为 NULL 和 stdio.h 中的所有内容(stderr、printf 等)获取了未解析的符号,但编译运行良好。在我进入项目属性并删除一堆不必要的 C/C++ 包含路径之前,没有任何帮助。之后,重新索引解决了问题。
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.
在另一种情况下,我有一个未定义的类名符号,该符号涉及某些条件预处理器宏技巧。将定义宏的头文件添加到 C/C++ 索引器选项中的“索引特定头文件的所有变体”(在选中“启用项目特定设置后”)修复了它。
This shows the the eclipse CDT indexer can get confused easily.
这表明 eclipse CDT 索引器很容易混淆。

