I am a beginner in programming.I try to compile a c program in linux, gcc written by the others and got the following error .
我是编程初学者。我尝试在linux中编译一个c程序,由其他人编写,并得到如下错误。
cmd.h:145: error: redefinition of ‘struct stat’.
cmd。h:145:错误:重新定义“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
似乎有人不止一次地定义了struct 'stat。但是由于有很多代码文件,我不知道如何解决它。关于那件事,谁能给我出主意?谢谢
4 个解决方案
#1
0
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
.
尝试使用grep -r“struct stat”*查找定义?首先尝试您自己的代码,然后检查/usr/include和/usr/local/ include。
#2
2
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.
我假设您尝试定义自己的结构类型,它已经在标准头文件中定义了。struct stat在sys/stat中定义。h看这里(包含文件统计信息),它直接或通过其他头文件。
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.
更好的方法是为类型定义使用前缀,例如,typedef struct myprog_cmd_stat{…};。后者还允许快速理解它的定义。
#3
#4
0
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.
用cc -E编译,它将产生预处理器输出。扫描出现的struct stat;由预处理器发出的#文件名lineno行将告诉您定义发生在何处。
=== 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 * occurs. I'll bet that you get similar messages and have simply overlooked it.
确切地说冲突发生在哪里。我敢打赌,你得到了类似的信息,只是忽略了它。
#1
0
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
.
尝试使用grep -r“struct stat”*查找定义?首先尝试您自己的代码,然后检查/usr/include和/usr/local/ include。
#2
2
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.
我假设您尝试定义自己的结构类型,它已经在标准头文件中定义了。struct stat在sys/stat中定义。h看这里(包含文件统计信息),它直接或通过其他头文件。
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.
更好的方法是为类型定义使用前缀,例如,typedef struct myprog_cmd_stat{…};。后者还允许快速理解它的定义。
#3
1
I would suggest to create a
makefile and use
make
to compile your code.
Example.
我建议创建一个makefile并使用make编译您的代码。的例子。
#4
0
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.
用cc -E编译,它将产生预处理器输出。扫描出现的struct stat;由预处理器发出的#文件名lineno行将告诉您定义发生在何处。
=== 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 * occurs. I'll bet that you get similar messages and have simply overlooked it.
确切地说冲突发生在哪里。我敢打赌,你得到了类似的信息,只是忽略了它。