开发者

redefinition of struct in linux GCC

I am a beginner in programming.I try to compile a c prog开发者_运维问答ram in linux, gcc written by the others and got the following error .

cmd.h:145: error: redefinition of ‘struct stat’.

It seems somebody has defined the struct 'stat' more than once. But since there are lots of code files, i dont know how to solve it.Can anyone advise me on that. Thanks


I suppose you try to define own structure type, which is already defined in standard headers. struct stat is defined in sys/stat.h see here (containing file stat info) and it's included directly or through other headers.

A better approach is to use prefix for your type definition, for example, typedef struct myprog_cmd_stat { ... }; . The latter will also allow to quickly understand where it's defined.


I would suggest to create a makefile and use make to compile your code. Example.


Try using grep -r "struct stat" * to find the definition? Try your own code first then check for definitions in /usr/include and /usr/local/include.


Compile with cc -E, which will produce the preprocessor output. Scan that for occurrences of struct stat; the # filename lineno lines emitted by the preprocessor will tell you where the definition occurs.

=== edit ===

Even better: Compiling

#include <sys/stat.h>

struct stat {};

produces the messages

foo.c:3:8: error: redefinition of ‘struct stat’
/usr/include/bits/stat.h:43:8: note: originally defined here

Which says exactly where the clash occurs. I'll bet that you get similar messages and have simply overlooked it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜