Error: redefinition of ‘xxx’ 问题解决

原帖在此,感谢这位作者

错误信息类似于

message.h:36:16: error: redefinition of 'struct MSG_SERVOCTRL'
message.h:36:16: note: originally defined here
message.h:40:2: error: conflicting types for 'servoctrl'
message.h:40:2: note: previous declaration of 'servoctrl' was here
message.h:42:16: error: redefinition of 'struct MSG_PTZCTRL'
message.h:42:16: note: originally defined here
message.h:51:2: error: conflicting types for 'ptzctrl'
message.h:51:2: note: previous declaration of 'ptzctrl' was here
message.h:55:20: error: redefinition of 'cameractrl_params'

一般是目标头文件.h没有加条件编译语句,语句的格式比较固定:

#ifndef _TEST_H_
#define _TEST_H_

//。。。

#endif

把上面的代码加在头文件.h的头尾,即可避免重复定义的错误。

#include “xxx.h” 实际是将.h文件内容展开铺在.c文件之前,如果xxx.h没有加条件编译,那么重复引用和循环递归include时,就会展开多个重复的定义在.c代码之前,这样在编译的时候必然会有重复定义的告警。

你可能感兴趣的:(专治各种不服,c语言,c++)