Reputation: 1
I am trying to compile multiple source files into a single module. I am having issues with multiple definition of functions.
Here is the code snippet of file1.c file
#include <linux/init.h>
#include <linux/module.h>
#include "headerfile.h"
#include <linux/slab.h>
static void swarm_init(void)
{
printk(KERN_ALERT "swarm_init function called\n");
}
void* func1(void) {
.....some code here
}
static void swarm_exit(void)
{
printk(KERN_ALERT "swarm_exit: exit function called");
}
module_init(swarm_init);
module_exit(swarm_exit);
Second file is as follows
#include <linux/init.h>
#include <linux/module.h>
#include "headerfile.h"
#include <linux/slab.h>
static void test_init(void)
{
printk(KERN_ALERT "Test init\n");
void *x;
x = func1();
}
static void test_exit(void)
{
printk(KERN_ALERT "test: exit function called");
}
module_init(test_init);
module_exit(test_exit);
headerfile.h is as follows
#ifndef _HEADERFILE_H
#define _HEADERFILE_H
typedef struct _hashmap_element{
int key;
int in_use;
void* data;
} hashmap_element;
typedef struct _hashmap_map{
int table_size;
int size;
hashmap_element *data;
} hashmap_map;
void *func1(void);
#endif
And my makefile is
obj-m :=myfile.o
myfile-objs := file1.o file2.o
all:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
clean:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
I keep getting multiple definition of init_module and cleanup_module.
any idea whats going wrong?
Upvotes: 0
Views: 3055
Reputation: 66153
Single module may have at most one initialization (declared with module_init()
macro) and one cleanup (module_exit()
) function. If you need initialization functionality for several parts of your module, you need to combine them manually into single initialization function. The same is true for cleanup.
Upvotes: 2