首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 操作系统 > UNIXLINUX >

驱动编译异常 variable `globalvar_fops' has initializer but incomplete type

2012-03-27 
驱动编译错误 variable `globalvar_fops has initializer but incomplete type#includelinux/module.h#

驱动编译错误 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_tglobalvar_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)
{
    intret;

    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)
{
    intret;

    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)
将#include   <linux/fs.h> 改为
#include   </usr/src/linux-2.4.20-8/include/linux/fs.h>
也不对

总是出现这样的错误:
variable   `globalvar_fops '   has   initializer   but   incomplete   type
storage   size   of   `globalvar_fops '   isn 't   known

这困扰我几天了,刚学习驱动就这样困难,请高手指点!!非常感谢!

[解决办法]
gcc -D _KERNEL_ -DMODULE -DLINUX -I /usr/src/linux-2.4.20-8/include -c -o globalvar.o globalvar.c

热点排行