#include <linux/version.h>
#include <linux/config.h>
#if CONFIG_MODVERSIONS==1
#define MODVERSIONS
#include <linux/modversions.h>
#endif
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
MODULE_LICENSE ("GPL");
static int hello_init(void)
{
printk("helloworld/n");
return 0;
}
static void hello_exit(void)
{
printk("GoodBye Cruel World/n");
}
module_init(hello_init);
module_exit(hello_exit);
编译命令:
gcc -Wall -DMODULE -D__KERNEL__ -DLINUX -c -o helloworld.o helloworld.c -I /usr/src/linux-2.4/include/
其中 -I /usr/src/linux-2.4/include/ 是用来指定头文件的路径
产生helloworld.o
insmod hello.o
rmmod hello
执行这两条命令后并没有在终端输出helloworld, goodbye cruel world!是因为printk输出优先级的问题,可以在终端下执行dmseg来查看输出!
在终端显示的问题等以后看到此知识点后再解决!
曾经出现过的问题比较普遍,可以查看以下两个帖子!
http://www.linuxsir.org/bbs/showthread.php?p=1216780
http://www.linuxsir.org/bbs/archive/index.php/t-42965.html