2.4 Hello World(P4):多文件模块
环境:Linux内核 2.6
1.示例代码(start.c和stop.c)
第一个文件start.c
/*
* start.c - Illustration of multi filed modules
*/
# include <linux/kernel.h> /* Wd're doing kernel work */
# include <linux/module.h> /* specifically, a module */
int init_module(void)
{
printk(KERN_INFO "Hello, world - This is the hernel speaking\n");
return 0;
}
第二个文件stop.c
/*
* stop.c - Illustartion of multi filed modules
*/
# include <linux/kernel.h>
# include <linux/module.h>
void cleanup_module()
{
printk(KERN_INFO "Short is the life of a kernel module\n");
}
MODULE_LICENSE("GPL");
2.多文件依赖的 Makefile文件的创建
obj-m += hello-2.o
obj-m += hello-3.o
obj-m += hello-4.o
obj-m += startstop.o
startstop-objs := start.o stop.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