[英]extern struct array error: array type has incomplete element type
I have 3 files: main.c
, def.c
, def.h
. 我有3个文件:
main.c
, def.c
, def.h
。 Both .c
files include def.h
. 这两个
.c
文件都包含def.h
All the files are in the same directory. 所有文件都在同一目录中。 My compiler is gcc version 4.9.2 .
我的编译器是gcc版本4.9.2 。
In def.h : 在def.h中 :
struct _info {
int a;
};
In def.c : 在def.c中 :
#include "def.h"
struct _info info[] = {};
And in main.c : 在main.c中 :
#include "def.h"
extern struct _info info[];
When I build def.c
as an object file and then build with main.c
like: 当我将
def.c
构建为目标文件,然后使用main.c
构建时,如下所示:
gcc -c def.c
gcc main.c def.o
And I got an error message: array type has incomplete element type 我收到一条错误消息: 数组类型具有不完整的元素类型
If I use typedef
to define struct _info
as INFO
like: 如果我使用
typedef
将struct _info
定义为INFO
例如:
typedef struct _info INFO;
And replace struct _info
with INFO
in .c
files. 并用
.c
文件中的INFO
替换struct _info
。 Compile ok then. 然后编译确定。
But why and what does typedef
do? 但是, 为什么 , 什么
typedef
呢?
Thanks for everybody's help. 感谢大家的帮助。 This question end up with a misspelling in
main.c
. 这个问题以
main.c
的拼写错误结束。 Something like: 就像是:
extern struct _infoo info[];
When typedef
replace them, all work fine definitely. 当
typedef
替换它们时,一切肯定可以正常工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.