我正在编写一个内核模块,其中有 3 个源文件和一个头文件。当我编译它时,它向我显示以下错误:
/home/karan/project/proc.o: In function `proc_read':
/home/karan/project/proc.c:23: multiple definition of `info'
/home/karan/project/main.o:/home/karan/project/main.c:23: first defined here
/home/karan/project/tx_pkt.o: In function `tx_packet':
/home/karan/project/tx_pkt.c:9: multiple definition of `info'
/home/karan/project/main.o:/home/karan/project/main.c:23: first defined here
我认为问题在于编译器struct info
不止一次地进行定义。但是解决方案是什么?struct info
是在头文件中声明的。头文件如下:
int proc_write(struct file *filp,const char *buffer,unsigned long count,void *data);
int proc_read(char *buffer,char **buffer_location,off_t offset,int buffer_length,int *eof,void *data);
void tx_packet(void);
#ifndef MYDEFS_H
#define MYDEFS_H
struct inform
{
char tx_buffer[100];
struct iphdr *ip1;
};
extern struct inform info;
#endif