不同的.c文件中使用同一个结构体
在fifo.h文件中定义一个结构体如下:
- C/C++ code
#ifndef _FIFO_H_#define _FIFO_H_typedef struct tagSTRUCT_FIFO_T{ int nWrite; int nRead; int nCount; int nSize; char acSrcStr[20];}FIFO_T;FIFO_T FIFO = {0,0,0,20,'\0'};#endif在main.c文件中#include "fifo.h",在write.c文件中也#include "fifo.h",为什么会不行?小弟初学者,用的是ubuntu,gcc编译,提示如下
/tmp/cccuv8sZ.o:(.data+0x0): multiple definition of `FIFO'
/tmp/ccOb2z8i.o:(.data+0x0): first defined here
collect2: ld returned 1 exit status
请大神帮忙,谢谢啦
[解决办法]
FIFO_T FIFO = {0,0,0,20,'\0'};不要放在.h文件中,放到write.c中,然后.h中extern FIFO_T FIFO;即可。
[解决办法]
可能FIFO在其它文件中已有定义,你换个名字看看。