【发布时间】:2012-03-28 06:44:08
【问题描述】:
我正在编写一个内核模块,其中有 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
【问题讨论】:
-
@phimuemue 我解决了实际上我在那里写了 struct info 的对象........
-
@torrential coding 嗨,我通过放置 extern struct info inf 解决了这个问题,但现在它给了我以下警告:WARNING: "info" [/home/karan/project/generate.ko] undefined!
-
@OliCharlesworth 谢谢,你可能是对的。我意识到我们只是移出了一些函数,没有结构。
-
@karan421 您是否尝试过我回答中的建议?
标签: c linux linux-kernel header-files multiple-definition-error