请教一下最新内核中模块程序的编译方法
我的书是用的2.2版本的内核 我用它上面的编译命令编译我的模块程序出很多错 不知道原因何在 书上说要引用的.h文件在/usr/src/linux/目录下 可是我没有这个目录 但我在/usr/include/linux/下找到了所有和书上同名的.h文件 不知行不行另外我手上两本书中的例程的拼写有出入 不清楚哪个是正确的
所以请牛人指点一下 最好有个现成的模块程序 我能参考一下
#include </usr/include/linux/kernel.h>
#include </usr/include/linux/module.h>
#include </usr/include/linux/proc_fs.h>
int myRead(char *sysBuffer,char **myBuffer,off_t offset,int len,int zero)
/*这个地方 一本书上的是 off_t 一本上是 loff_t 不知道哪个是正确的?*/
{
}
struct proc_dir_entry myModProcFile=
{
0,
8,
"myModule",
S_IFREG|S_IRUGO,
1,
0,
0,
80,
NULL,
myRead,
NULL
}
int init_module()
{
return proc_register(&proc_root,&myModProcFile);
}
void cleanup_module()
{
proc_unregister(&proc_root,0);
}
我用的编译命令是 gcc -C -Wall -D__KERNEL__ -DMODULE myModule.c
出现的错误信息如下:
myModule.c:5: error: syntax error before "off_t"
myModule.c:10: error: variable `myModProcFile' has initializer but incomplete type
myModule.c:12: warning: excess elements in struct initializer
myModule.c:12: warning: (near initialization for `myModProcFile')
myModule.c:13: warning: excess elements in struct initializer
myModule.c:13: warning: (near initialization for `myModProcFile')
myModule.c:14: warning: excess elements in struct initializer
myModule.c:14: warning: (near initialization for `myModProcFile')
myModule.c:15: error: `S_IFREG' undeclared here (not in a function)
myModule.c:15: error: `S_IRUGO' undeclared here (not in a function)
myModule.c:15: warning: excess elements in struct initializer
myModule.c:15: warning: (near initialization for `myModProcFile')
myModule.c:16: warning: excess elements in struct initializer
myModule.c:16: warning: (near initialization for `myModProcFile')
myModule.c:17: warning: excess elements in struct initializer
myModule.c:17: warning: (near initialization for `myModProcFile')
myModule.c:18: warning: excess elements in struct initializer
myModule.c:18: warning: (near initialization for `myModProcFile')
myModule.c:19: warning: excess elements in struct initializer
myModule.c:19: warning: (near initialization for `myModProcFile')
myModule.c:20: error: `NULL' undeclared here (not in a function)
myModule.c:20: warning: excess elements in struct initializer
myModule.c:20: warning: (near initialization for `myModProcFile')
myModule.c:21: warning: excess elements in struct initializer
myModule.c:21: warning: (near initialization for `myModProcFile')
myModule.c:23: warning: excess elements in struct initializer
myModule.c:23: warning: (near initialization for `myModProcFile')
myModule.c:25: error: syntax error before "int"
myModule.c: In function `cleanup_module':
myModule.c:32: error: `proc_root' undeclared (first use in this function)
myModule.c:32: error: (Each undeclared identifier is reported only once
myModule.c:32: error: for each function it appears in.)
myModule.c: At top level:
myModule.c:10: error: storage size of `myModProcFile' isn't known
请大家帮帮忙 谢谢了!
页:
[1]