linux 内核驱动编译简单示例

hello.c

#include <linux/module.h>
#include <linux/init.h>

static int __init hello_init(void)
{
    printk(KERN_ALERT "Hello,world!\n");
    return 0;  
}

static void __exit helo_exit(void)
{
    printk(KERN_ALERT "GoodBye,cruel world!\n");
}

module_init(hello_init);
module_exit(hello_exit);
MODULE_LICENSE("Dual BSD/GPL");
MODULE_AUTHOR("codingbug");
MODULE_DESCRIPTION("STUDY_MODULE");

Makefile

View Code
1 obj-m += hello.o
2 KDIR:=/lib/modules/$(shell uname -r)/build
3 all:
4     make -C $(KDIR) M=$(PWD) modules
5 clean:
6     make -C $(KDIR) M=$(PWD) clean

 

 

 

  

posted @ 2012-10-03 14:13  断缠子  阅读(421)  评论(0编辑  收藏  举报
看不到我把