Question

I am writing a kernel module in which i have 3 source files and one header file. When I compile it, it shows me the following error:

/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

I think the problem is the compiler is taking definition struct info more then once. But what is the solution? The struct info is declared in the header file . The header file is as follow:

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
Was it helpful?

Solution

Use : header guards

In your header do this:

#ifndef MYDEFS_H
#define MYDEFS_H

struct info {
    ...
    ...
};

#endif

OTHER TIPS

I think You added the main .c file in ($(USERAPPS): $(USERSP) $(CC) -o $@ ) here, U include all c file except main file here

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top