eclipse C 项目显示错误(符号无法解析)但可以编译

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13269092/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 19:21:37  来源:igfitidea点击:

eclipse C project shows errors (Symbol could not be resolved) but it compiles

ceclipseindexing

提问by brimborium

I have got access to a C project at work that I have to implement some stuff in. I was able to load it into eclipse and can Project -> Build Allit. Compilation shows no errors or warnings. But in eclipse, there are a lot of errors shown. One example:

我在工作中可以访问一个 C 项目,我必须在其中实现一些东西。我能够将它加载到 eclipse 中并且可以Project -> Build All。编译没有显示错误或警告。但是在eclipse中,显示了很多错误。一个例子:



There is an enum

有一个枚举

typedef enum MeasurementType {
    PN, BB, AM, RES
} MEAS_TYPE;
MEAS_TYPE type;

in one of the files. It is used somewhere else and produces an error like this: enter image description here

在其中一个文件中。它在其他地方使用并产生如下错误: 在此处输入图片说明

It is most interesting, that only AMseems to be a problem, not PNor BB.

最有趣的是,这AM似乎只是一个问题,而不是PNBB



I haven't found a satisfying solution to this. I already tried to include all possible directories I could think of in Project Properties -> C/C++ General -> Paths and Symbols(like this postsuggests), but that didn't help.

我还没有找到令人满意的解决方案。我已经尝试包括我能想到的所有可能的目录Project Properties -> C/C++ General -> Paths and Symbols(就像这篇文章建议的那样),但这没有帮助。

The project itself is compiled with Makefiles (which is why I need Project -> Build All). Can it be that eclipse does not interpret those Makefiles correctly or something? I am a bit lost after messing around with that stuff for a few hours and not getting a single step forward.

项目本身是用 Makefiles 编译的(这就是我需要的原因Project -> Build All)。是不是 eclipse 没有正确解释这些 Makefile 之类的?在把这些东西弄乱了几个小时并且没有向前迈出一步后,我有点迷失了。

EDIT: Here are some screenshots for my build-relevant project properties (at least I believe they are relevent :D). Tell me if you need more information.

编辑:这是我的构建相关项目属性的一些屏幕截图(至少我相信它们是相关的:D)。如果您需要更多信息,请告诉我。

enter image description hereenter image description here

在此处输入图片说明在此处输入图片说明

采纳答案by alk

It looks as if Eclipse (not gcc) is setup to parse the wrong or some additonally, propably outdated (include) source files.

看起来好像 Eclipse(不是 gcc)被设置为解析错误的或一些额外的、可能过时的(包含)源文件。

回答by brimborium

Since I got a suggestion from moooeeeep, I will post the solution here. I am still accepting alk's answer, because he was the one that showed me towards the right direction.

由于我得到了 moooeeeeep 的建议,我将在这里发布解决方案。我仍然接受 alk 的回答,因为他是向我指明正确方向的人。

My solution:

我的解决方案:

If I click on AMin eclipse (the one that is underlined with red) and press F3to go to the declaration, it actually asked me to which declaration I want to go. It listed the (correct) enum constant as well as some variable from somewhere else. Therefore the problem was that multiple declarations of AMwere present in different code locations.

如果我AM在 eclipse(用红色下划线的那个)点击并按F3下去声明,它实际上问我我想去哪个声明。它列出了(正确的)枚举常量以及来自其他地方的一些变量。因此,问题是AM在不同的代码位置存在多个声明。

I fixed this problem by just renamingthe enumconstant to something else (ANin my case). There is no variable with the same name in the code and therefore eclipse was able to refactor it correctly.

我刚好解决了这个问题,重命名enum常量,其他的东西(AN在我的情况)。代码中没有同名的变量,因此 eclipse 能够正确重构它。

回答by Compfy

There is a bug report added in Eclipse CDT Bugzilla with regard to this problem: https://bugs.eclipse.org/bugs/show_bug.cgi?id=439553

在 Eclipse CDT Bugzilla 中添加了一个关于此问题的错误报告:https://bugs.eclipse.org/bugs/show_bug.cgi?id =439553

回答by Pyves

This is quite an old question, but I hope this short answer can be useful to someone.

这是一个很老的问题,但我希望这个简短的回答对某人有用。

I was having similar errors with enums in the IDE but not when compiling, which seemed to indicate a bug in Eclipse's Codan. After upgrading to the new version of Eclipse (Neon 4.6) released in June, the errors have disappeared. Just try updating Eclipse!

我在 IDE 中遇到类似的枚举错误,但在编译时没有,这似乎表明 Eclipse 的 Codan 中存在错误。升级到6月份发布的新版Eclipse(Neon 4.6)后,错误消失。只需尝试更新 Eclipse!