LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 565|回复: 1

不知道那里错了,有人知道吗?

[复制链接]
发表于 2005-7-30 14:57:43 | 显示全部楼层 |阅读模式
照猫画虎写了个字符设备驱动,不过该如何编译啊?  

gcc  -c  myfirstdev.c  -D_KERNEL_  -DMODULE  -O2  -I/usr/src/linux-2.4.20-8/include  -g  -Wall  -o  myfirstdev.o  
结果是:  
In  file  included  from  /usr/src/linux-2.4.20-8/include/linux/sched.h:16,  
                                 from  /usr/src/linux-2.4.20-8/include/asm/uaccess.h:8,  
                                 from  myfirstdev.c:6:  
/usr/src/linux-2.4.20-8/include/linux/timex.h:173:  field  `time'  has  incomplete  type  
/usr/src/linux-2.4.20-8/include/linux/timex.h:188:  confused  by  earlier  errors,  bailing  out  
这些错好像都是指向内核中的。  


#include  <linux/module.h>  
#include  <linux/kernel.h>  
#include  <linux/fs.h>  
#include  <linux/types.h>  
#include  <linux/slab.h>  
#include  <asm/uaccess.h>  
#include  <asm/page.h>  
#include  <linux/errno.h>  
#include  <linux/config.h>  


static  test_major=254;  

ssize_t  test_read(struct  file  *filp,char  *buf,size_t  count,loff_t  *f_pos);  
static  ssize_t  test_write(struct  file  *filp,const  char  *buf,size_t  count,loff_t  *ppos);  
int  test_open(struct  inode  *inode,struct  file  *filp);  
int  test_release(struct  inode  *inode,struct  file  *filp);  

struct  file_operations  test_ops={  
           open:            test_open,  
           release:test_release,  
           read:            test_read,  
           write:            test_write,  
};  

sszie_t  test_read(struct  file  *filp,char  *buf,size_t  count,loff_t  *f_pos)  
{  
           //read  operation  
           printk("read  operation\n");  
}  

static  ssize_t  test_write(struct  file  *filp,const  char  *buf,size_t  count,loff_t  *ppos)  
{  
           //write  operation  
           printk("write  operation\n");  
}  

int  test_open(struct  inode  *inode,struct  file  *filp)  
{  
           //open  operation  
           MOD_INC_USE_COUNT;  
           printk("open  operation\n");  
           return  0;  
}  
   
int  test_release(struct  inode  *inode,struct  file  *filp)  
{  
           //release  operation  
           MOD_DEC_USE_COUNT;  
           printk("release  operation\n");  
}  

int  init_module(void)  
{  
           int  result;  
           printk("init  module  operation\n");  
           result=register_chrdev(test_major,"test",&test_ops);  
           printk("Major  is  %d!\n",test_major);  
           return  0;  
}  

void  cleanup_module(void)  
{  
           unregister_chrdev(test_major,"test");  
           printk("exit  module\n");  
}
发表于 2005-7-30 15:34:45 | 显示全部楼层
Have you installed the sources of kernel?
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表