首页 / 操作系统 / Linux / Linux内核模块编译 最简单的hello world
驱动源代码可用,只是MODULE_LICENCE行老报错,加上#也不行,就注释掉了后注:lincese拼错了,应该是MODULE_LICENSE//hello world driver for linux 2.6
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/module.h>
//MODULE_LICENCE("GPL");
static int __init hello_init(void)
{
printk(KERN_ALERT "Hello, world! from kernel space....
");
return 0;
}
static void __exit hello_exit(void)
{
printk(KERN_ALERT "Goodbye, world! Leaving kernel space....
");
}
module_init(hello_init);
module_exit(hello_exit); Makefile文件obj-m += hello.o
all:
make -C /lib/modules/`uname -r`/build SUBDIRS=$(PWD) modules
clean:
make -C /lib/modules/`uname -r`/build SUBDIRS=$(PWD) clean插入模块#insmod hello.ko查看模块插入情况#lsmod | grep hello#tail /var/log/messages移除模块#rmmod hello#taile /var/log/messages