模块中调用另外一个模块中的函数
时间:2009-04-11 来源:ubuntuer
最简单的示例程序,写两个模块,分别为A和B,在A中导出了一些函数,而在B中使用A导出的函数。模块都使用GPL。
两个模块的源码如下:
C/C++ code
C/C++ code
Makefile for Module A
BatchFile code
Makefile for Module B
BatchFile code
原文地址 http://topic.csdn.net/u/20081009/11/6fb7295c-0d30-4d4f-b390-af4413aa7f7e.html
两个模块的源码如下:
C/C++ code
// Module A (mod_a.c)
#include<linux/init.h>
#include<linux/module.h>
#include<linux/kernel.h>
static int func1(void)
{
printk("In Func: %s...\n",__func__);
return 0;
}
// Export symbol func1
EXPORT_SYMBOL(func1);
static int __init hello_init(void)
{
printk("Module 1,Init!\n");
return 0;
}
static void __exit hello_exit(void)
{
printk("Module 1,Exit!\n");
}
module_init(hello_init);
module_exit(hello_exit);
C/C++ code
// Module B (mod_b.c)
#include<linux/init.h>
#include<linux/kernel.h>
#include<linux/module.h>
static int func2(void)
{
extern int func1(void);
func1();
printk("In Func: %s...\n",__func__);
return 0;
}
static int __init hello_init(void)
{
printk("Module 2,Init!\n");
func2();
return 0;
}
static void __exit hello_exit(void)
{
printk("Module 2,Exit!\n");
}
module_init(hello_init);
module_exit(hello_exit);
Makefile for Module A
BatchFile code
obj-m += mod1.o
mod1-y := mod_a.o
KVERSION = $(shell uname -r)
all:
make -C /lib/modules/$(KVERSION)/build M=$(PWD) modules
clean:
make -C /lib/modules/$(KVERSION)/build M=$(PWD) clean
rm -f *.o *.ko *.cmd
Makefile for Module B
BatchFile code
obj-m += mod2.o
mod2-y := mod_b.o
KVERSION = $(shell uname -r)
all:
make -C /lib/modules/$(KVERSION)/build M=$(PWD) modules
clean:
make -C /lib/modules/$(KVERSION)/build M=$(PWD) clean
rm -f *.o *.ko *.cmd
原文地址 http://topic.csdn.net/u/20081009/11/6fb7295c-0d30-4d4f-b390-af4413aa7f7e.html
相关阅读 更多 +