【发布时间】:2010-12-11 03:02:02
【问题描述】:
希望这是一个简单的问题...这是我重现此问题的过程。首先我创建我的源文件:
bash $ cat t.c
#include "t.h"
int main()
{
ABC abc;
}
然后我创建我对应的头文件:
bash $ cat t.h
#ifdef _T_H
#define _T_H
#ifdef __cplusplus
extern "C" {
#endif
typedef struct abc {
int a;
} ABC;
#ifdef __cplusplus
}
#endif
#endif
然后,我尝试编译它:
bash $ gcc -o t t.c
t.c: In function ‘main’:
t.c:5: error: ‘ABC’ undeclared (first use in this function)
t.c:5: error: (Each undeclared identifier is reported only once
t.c:5: error: for each function it appears in.)
t.c:5: error: expected ‘;’ before ‘abc’
发生了什么事?如果我使用 'struct abc' 而不是 'ABC' 作为 t.c 中的类型,那么它会编译。为什么 typedef 不起作用?
【问题讨论】:
标签: c gcc compiler-construction header