无法解析eclipse CDT中的符号

无法解析eclipse CDT中的符号,c,eclipse,eclipse-cdt,C,Eclipse,Eclipse Cdt,这是一个关于堆栈溢出的常见问题,但我的案例很奇怪,我找不到合适的答案,所以我仍在发布它 这是一个很大的项目,但这个问题只包含五个文件:types.h、glob.h、test.c、test.h和main.c 在types.h中,假设我定义了一个结构: struct s_foo { int a; }; 在glob.h struct s_foo *foo; 在测试中.h #ifndef GLOB_H #define GLOB_H extern struct s_foo *foo; #end

这是一个关于堆栈溢出的常见问题,但我的案例很奇怪,我找不到合适的答案,所以我仍在发布它

这是一个很大的项目,但这个问题只包含五个文件:types.h、glob.h、test.c、test.h和main.c

types.h中,假设我定义了一个结构:

struct s_foo {
    int a;
};
glob.h

struct s_foo *foo;
测试中.h

#ifndef GLOB_H
#define GLOB_H
extern struct s_foo *foo;
#endif
test.c中

#include "types.h"
#include "test.h"
struct s_foo *foo = NULL;
#include "types.h"
#include "test.h"
...
foo = (struct s_foo *)malloc(sizeof(struct s_foo));
main.c中

#include "types.h"
#include "test.h"
struct s_foo *foo = NULL;
#include "types.h"
#include "test.h"
...
foo = (struct s_foo *)malloc(sizeof(struct s_foo));
该程序可由gcc编译,运行良好,但eclipse在main.c中给了我一个恼人的错误,符号“foo”无法解析

谁能告诉我为什么eclipse会给我这个错误?这是因为变量foo的多重定义吗


谢谢

确保eclipse可以看到您的所有.h文件。对我来说,它似乎不包括所有相关的.h文件

对于从Visual Studio 2013移植的代码,我在Eclipse上也有同样的问题。我最好的猜测是编译器无法进行多次正确的符号扫描。因此,我的最终解决方案是在出现错误的文件中再添加一个声明。对于你的情况,我建议你加上

外部结构s_foo*foo


在main.c文件中的error语句之前,请给出一个提示:在头文件中定义变量不是一个好的做法。这是“多定义”容易出错的。它是在“glob.h”中定义的,现在问题是符号无法解决。我想知道eclipse是否无法确定foo是在test.h还是glob.h中定义的,所以它给出了无法解析的符号?