LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 1071|回复: 5

简单的module编译的问题?

[复制链接]
发表于 2006-5-6 11:59:00 | 显示全部楼层 |阅读模式
刚开始学写module,就是简单的hello。
hello-1.c
  1. /*  
  2. *  hello-1.c - Demonstrating the module_init() and module_exit() macros.
  3. *  This is preferred over using init_module() and cleanup_module().
  4. */
  5. #include <linux/module.h>        /* Needed by all modules */
  6. #include <linux/kernel.h>        /* Needed for KERN_INFO */
  7. #include <linux/init.h>                /* Needed for the macros */

  8. static int __init hello_2_init(void)
  9. {
  10.         printk(KERN_INFO "Hello, world 2\n");
  11.         return 0;
  12. }

  13. static void __exit hello_2_exit(void)
  14. {
  15.         printk(KERN_INFO "Goodbye, world 2\n");
  16. }

  17. module_init(hello_2_init);
  18. module_exit(hello_2_exit);
复制代码

Makefile:
  1. obj-m += hello-1.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

复制代码

mak后的结果:
  1. make -C /lib/modules/2.6.16-1-486/build M=/home/guoxi/code/module modules
  2. make[1]: Entering directory `/usr/src/linux-headers-2.6.16-1-486'
  3.   Building modules, stage 2.
  4.   MODPOST
  5. make[1]: Leaving directory `/usr/src/linux-headers-2.6.16-1-486'
  6. guoxi:/home/guoxi/code/module# make
  7. make -C /lib/modules/2.6.16-1-486/build M=/home/guoxi/code/module modules
  8. make[1]: Entering directory `/usr/src/linux-headers-2.6.16-1-486'
  9.   Building modules, stage 2.
  10.   MODPOST
  11. make[1]: Leaving directory `/usr/src/linux-headers-2.6.16-1-486'
复制代码

目录下没有.ko文件,那里有问题阿?
发表于 2006-5-6 12:40:03 | 显示全部楼层
没有 .config 怎能 make?就算用 make oldconfig 也要把 .config 拷到 kernel source tree 下才能用!
回复 支持 反对

使用道具 举报

 楼主| 发表于 2006-5-6 12:44:06 | 显示全部楼层
哦,那个问题我知道了。
要编译module的话,要装linux-headers,不是linux-source。
我装了linux-headers后,编译没有.ko文件??
回复 支持 反对

使用道具 举报

发表于 2006-5-6 12:51:20 | 显示全部楼层
Post by forexi
哦,那个问题我知道了。
要编译module的话,要装linux-headers,不是linux-source。
我装了linux-headers后,编译没有.ko文件??
没有 source 怎样编译 module?:ask
回复 支持 反对

使用道具 举报

 楼主| 发表于 2006-5-6 13:22:25 | 显示全部楼层
但是我装了linux-headers后,
有/usr/src/linux-headers-2.6.16-1-486 这个目录。
而/lib/modules/2.6.16-1-486/build指向这个目录。
就是Makefile中的/lib/modules/$(shell uname -r)/build指向的目录。
看来好像确实不用source吧?
回复 支持 反对

使用道具 举报

发表于 2006-5-6 18:12:26 | 显示全部楼层
没有源码,只有头文件跟本无法编译的说。。。
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表