No.11478 作者:ydfq 邮件:1154493577@qq.com ID:129773 登陆:7次 文章数:41篇 最后登陆IP:60.176.87.66 最后登陆:2013/7/30 14:05:01 注册:2010/12/21 17:16:13 财富:155 发帖时间:2011/1/25 14:48:43 发贴者IP:218.108.223.167 标题:ydfq:hello内核模块编译的全过程 摘要:No.11478hello内核模块编译的全过程 内核版本:2.6.10 在/home/tmp/下建立两个文件hello.c,Makefile hello.c ------------ #include <linux/init.h> #include <linux/kernel.h> #include <linux/module.h> MODULE_LICENSE("GPL"); static int hello_init(void) { printk(KERN_ALERT "hello module init\n"); return 0; } static void hello_exit(void) { printk(KERN_ALERT "hello module exit\n"); } module_init(hello_init); module_exit(hello_exit); -------------- Makefile ---------- ifneq ($(KERNELRELEASE),) obj-m := hello.o else KERNELDIR := /lib/modules/$(shell uname -r)/build PWD := $(shell pwd) default: $(MAKE) -C $(KERNELDIR) M=$(PWD) modules endif clean: rm -f *.ko *.mod.c *.mod.o *.o ----------- 编译模块 #make 清除 #make clean ----------- 为了能够在终端显示信息,要修改 /lib/modules/2.6.10/build/include/linux/kernel.h 文件的KERN_ALERT宏。 #define KERN_ALERT " <1> " 修改为 #define KERN_ALERT " <0> " ......
>>返回讨论的主题
|