Linux第一个驱动程序hello world编译
Linux第一个驱动程序hello world编译
Makefile
注意点:在vscode里面编辑器会将tab转换为空格,导致编译时报错Makefile:****missing separator. stop, 需要在gedit里面确认格式
1 2 3 4 5 6 7 8 9
| KERN_DIR = /lib/modules/`uname -r`/build
all: make -C $(KERN_DIR) M=$(PWD) modules
clean: make -C $(KERN_DIR) M=$(PWD) clean
obj-m += hello_world.o
|
- hello_world.c
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| #include <linux/init.h> #include <linux/module.h>
MODULE_LICENSE("GPL");
static int hello_init(void) { printk(KERN_INFO"Hello World enter\n"); return 0; }
static void hello_exit(void) { printk(KERN_INFO"Hello World exit\n "); }
module_init(hello_init); module_exit(hello_exit);
MODULE_AUTHOR("hi"); MODULE_DESCRIPTION("hello"); MODULE_ALIAS("world");
|
- 在同一目录下make后,insmod,rmmod测试