Chinaunix首页 | 论坛 | 博客
  • 博客访问: 16114
  • 博文数量: 3
  • 博客积分: 75
  • 博客等级: 民兵
  • 技术积分: 35
  • 用 户 组: 普通用户
  • 注册时间: 2011-03-14 23:50
文章分类
文章存档

2011年(3)

最近访客

分类: LINUX

2011-04-01 13:20:24

  1. 昨天试着学习写一个内核驱动模块,安装 kernel-package后,照着《Linux设备驱动程序第三版》的helloWorld程序写了如下源码:
  2. #include <linux/kernel.h>
  3. #include <linux/init.h>
  4. #include <linux/module.h>
  5. MODULE_LICENSE("Dual BSD/GPL");
  6. static int __init hello_init(void){
  7.     printk(KERN_ALERT "hello from hello world\n");
  8.     return 0;
  9. }
  10. static void __exit hello_exit(void){
  11.     printk(KERN_ALERT "goodbye from hello world\n");
  12. }
  13. module_init(hello_init);
  14. module_exit(hello_exit);
  15. 但是上面没有给出Makefile,头疼的我只有在网上找了下,后来经过我整合后,发现如下Makefile能够通过编译
  16. 必须要注意的是,Makefile的大小写问题,如果你Makefile写成了makefile ,make一样会报错的。(所有操作在root下进行)
  17. 我的测试环境是Ubuntu10.10。然后insmod hello.ko;dmesg | tail就能看到效果啦!
    1. obj-m := hello.o
    2. all:
    3.     make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
    4. clean:
    5.     make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
阅读(1135) | 评论(0) | 转发(0) |
0

上一篇:没有了

下一篇:使用indent进行源代码格式优化

给主人留下些什么吧!~~