|
|
刚开始学写module,就是简单的hello。
hello-1.c
- /*
- * hello-1.c - Demonstrating the module_init() and module_exit() macros.
- * This is preferred over using init_module() and cleanup_module().
- */
- #include <linux/module.h> /* Needed by all modules */
- #include <linux/kernel.h> /* Needed for KERN_INFO */
- #include <linux/init.h> /* Needed for the macros */
- static int __init hello_2_init(void)
- {
- printk(KERN_INFO "Hello, world 2\n");
- return 0;
- }
- static void __exit hello_2_exit(void)
- {
- printk(KERN_INFO "Goodbye, world 2\n");
- }
- module_init(hello_2_init);
- module_exit(hello_2_exit);
复制代码
Makefile:
- obj-m += hello-1.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
复制代码
mak后的结果:
- make -C /lib/modules/2.6.16-1-486/build M=/home/guoxi/code/module modules
- make[1]: Entering directory `/usr/src/linux-headers-2.6.16-1-486'
- Building modules, stage 2.
- MODPOST
- make[1]: Leaving directory `/usr/src/linux-headers-2.6.16-1-486'
- guoxi:/home/guoxi/code/module# make
- make -C /lib/modules/2.6.16-1-486/build M=/home/guoxi/code/module modules
- make[1]: Entering directory `/usr/src/linux-headers-2.6.16-1-486'
- Building modules, stage 2.
- MODPOST
- make[1]: Leaving directory `/usr/src/linux-headers-2.6.16-1-486'
复制代码
目录下没有.ko文件,那里有问题阿? |
|