redefinition of ‘struct‘ 报错
@redefinition of ‘struct’ 报错linux 环境下用c语言编程,出现redefinition of ‘struct’ 报错刚刚开始在linux下编程很多东西不熟练,在编译的过程中出现错误redefinition of ‘struct’解决办法首先是因为我在"Mapping.h"这个头文件中定义了一个结构体:typedef struct _node {char k[LEN];
文章共402字 · 阅读需要大约2分钟
一键AI生成摘要,助你高效阅读
问答
·
@redefinition of ‘struct’ 报错
linux 环境下用c语言编程,出现redefinition of ‘struct’ 报错
刚刚开始在linux下编程很多东西不熟练,在编译的过程中出现错误redefinition of ‘struct’
类似于头文件重复包含(假设头文件A.h中包含头文件C.h,同时头文件
B.h中也包含C.h,而在源文件中同时包含了A.h和B.h。这样编译器编译时就会出现头文件C.h重复包含的问题。)
解决办法
首先是因为我在"Mapping.h"这个头文件中定义了一个结构体:
typedef struct _node {
char k[LEN];
char v[LEN];
struct _node *next;
} Node;
错误就是这个结构体引起的
解决办法
#ifndef MAPPING
#define MAPPING
typedef struct _node {
char k[LEN];
char v[LEN];
struct _node *next;
} Node;
这里用到了三个语句:#ifndef MAPPING // MAPPING改成你的头文件名字
#define MAPPING
最后在结尾处加上 #endif
更多推荐
已为社区贡献1条内容
所有评论(0)