|
示例模块代码如下:
---------------------------------------------------------
//It is copied from a book
#ifndef __KERNEL__
#define __KERNEL__
#endif
#ifndef MODULE
#define MODULE
#endif
#include </usr/src/linux-2.4.20-8/include/linux/kernel.h> /*We'ar doing kernel
work*/
#include </usr/src/linux-2.4.20-8/include/linux/module.h> /*Specifically a mod
ule*/
/*Deal with CONFIG_MODVERSIONS>*/
#if CONFIG_MODVERSIONS==1
#define <linux/modversions.h>
#endif
/*Initialize the module*/
int init_module()
{
printk("Hello. World _ this is the kernel speaking\n");
/* If we returned a non zero value, it means that
* init_module failed and the kernel module can't be loaded*/
return 0;
}
/*cleanup - undid whatever init_module did */
void cleanup_module()
{
printk("Short is the file of the kernel module\n");
}
-------------------------------------------------------------
编译后加载,所有信息如下
[root@qg dd]# gcc -c helloword.c
In file included from /usr/src/linux-2.4.20-8/include/linux/module.h:25,
from helloword.c:11:
/usr/include/asm/atomic.h:40:2: warning: #warning Using kernel header in userl
and program. BAD!
[root@qg dd]# /sbin/insmod ./helloword.o
./helloword.o: kernel-module version mismatch
./helloword.o was compiled for kernel version 2.4.20
while this kernel is version 2.4.20-8.
怎样做才能够加载成功啊?谢谢.:help :help :help |
|