Reputation: 136
I have 3 files: main.c
, def.c
, def.h
. Both .c
files include def.h
.
All the files are in the same directory.
My compiler is gcc version 4.9.2.
In def.h:
struct _info {
int a;
};
In def.c:
#include "def.h"
struct _info info[] = {};
And in 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:
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;
And replace struct _info
with INFO
in .c
files.
Compile ok then.
But why and what does typedef
do?
Upvotes: 0
Views: 1692
Reputation: 136
Thanks for everybody's help. This question end up with a misspelling in main.c
.
Something like:
extern struct _infoo info[];
When typedef
replace them, all work fine definitely.
Upvotes: 1