阅读:3203回复:3
编译驱动错误 variable `globalvar_fops' has initializer but incomplete type
#include <linux/module.h>
#include <linux/init.h> #include </usr/src/linux-2.4.20-8/include/linux/fs.h> #include <asm/uaccess.h> #include <linux/kernel.h> #include <errno.h> #ifndef __KERNEL__ #define __KERNEL__ #endif #ifndef MODULE #define MODULE #endif MODULE_LICENSE ("GPL"); #define MAJOR_NUM 254 static ssize_t globalvar_read(struct file *, char *, size_t , loff_t * ); static ssize_t globalvar_write(struct file *, const char *, size_t , loff_t *); static int global_var=0; static ssize_t globalvar_read(struct file *filp, char * buf, size_t len, loff_t *off) { if(copy_to_user(buf, &global_var, sizeof(int))) { return -EFAULT; } return sizeof(int); } static ssize_t globalvar_write(struct file *filp, const char *buf, size_t len, loff_t *off) { if(copy_from_user(&global_var, buf,sizeof(int))) { return -EFAULT; } return sizeof(int); } static struct file_operations globalvar_fops = { read: globalvar_read, write: globalvar_write, } ; static int __init globalvar_init(void) { int ret; ret = register_chrdev(MAJOR_NUM, "glovalvar", &globalvar_fops); if(ret) { printk("global register failure"); } else { printk("global register sucess"); } return ret; } static int __exit globalvar_exit(void) { int ret; ret = unregister_chrdev(MAJOR_NUM, "globalvar"); if(ret) { printk("gloval unregister failure"); } else { printk("global unregistr success"); } return ret; } module_init(globalvar_init); module_exit(globalvar_exit); 编译之 [root@localhost xu]# gcc -D_KERNEL_ -DMODULE -DLINUX -I /usr/src/linux-2.4.20-8/include -c -o globalvar.o globalvar.c ............ globalvar.c: At top level: globalvar.c:23: warning: `struct file' declared inside parameter list globalvar.c:23: warning: its scope is only this definition or declaration, which is probably not what you want globalvar.c:24: warning: `struct file' declared inside parameter list globalvar.c:30: warning: `struct file' declared inside parameter list globalvar.c:31: conflicting types for `globalvar_read' globalvar.c:23: previous declaration of `globalvar_read' globalvar.c:41: warning: `struct file' declared inside parameter list globalvar.c:42: conflicting types for `globalvar_write' globalvar.c:24: previous declaration of `globalvar_write' globalvar.c:51: variable `globalvar_fops' has initializer but incomplete type globalvar.c:53: unknown field `read' specified in initializer globalvar.c:53: warning: excess elements in struct initializer globalvar.c:53: warning: (near initialization for `globalvar_fops') globalvar.c:54: unknown field `write' specified in initializer globalvar.c:54: warning: excess elements in struct initializer globalvar.c:54: warning: (near initialization for `globalvar_fops') globalvar.c: In function `__cleanup_module_inline': globalvar.c:96: warning: return from incompatible pointer type globalvar.c: At top level: globalvar.c:51: storage size of `globalvar_fops' isn't known 我是在 red hat 9 下编译的 usr/src/linux-2.4.20-8/include 是安装时自带的源码目录 gcc是red hat 9 自带的 gcc version 3.2.2 20030222 (Red Hat Linux 3.2.2-5) 总是出现这样的错误: variable `globalvar_fops' has initializer but incomplete type storage size of `globalvar_fops' isn't known 这困扰我几天了,刚学习驱动就这样困难,请高手指点!!非常感谢! |
|
沙发#
发布于:2007-06-01 11:02
ssize_t (*read) (struct file *, char __user *, size_t, loff_t *);
ssize_t (*write) (struct file *, const char __user *, size_t, loff_t *); static ssize_t globalvar_read(struct file *, char *, size_t , loff_t * ); static ssize_t globalvar_write(struct file *, const char *, size_t , loff_t *); do you find some thing different? yes! |
|
|
板凳#
发布于:2007-06-26 14:07
Re:编译驱动错误 variable `globalvar_fops' has initi
但是 那个应该不是问题的关键所在吧 |
|
地板#
发布于:2007-07-12 11:19
请问这类问题斑竹解决了没有?
|
|