阅读:989回复:0
各位大哥,编译出问题,求救!
各位大哥,一下是我的驱动程序,从书上抄的
#include <linux/module.h> #include <linux/sched.h> #include <linux/errno.h> #include <linux/mm.h> #include <linux/init.h> #if CONFIG_MODVERSIONS==1 #define MODVERSIONS #include <linux/modversions.h> #endif #include <linux/fs.h> #include <linux/wrapper.h> #ifndef KERNEL_VERSION #define KERNEL_VERSION(a,b,c) ((a)*65536+(b)*256+(c)) #endif #if LINUX_VERSION_CODE > KERNEL_VERSION(2,4,0) #include <asm/uaccess.h> #endif #define SUCCESS 0 #define DEVICE_NAME "char_dev" #define BUF_LEN 100 static int Device_Open = 0; static char Message[BUF_LEN]; static char *Message_Ptr; static int Major; static ssize_t device_read(struct file *file,char *buffer,size_t length,loff_t * offset) { int bytes_read = 0; if(*Message_Ptr == 0) return 0; while(length&&*Message_Ptr){ copy_to_user(buffer++,*(Message_Ptr++),length--); bytes_read++; } #ifdef DEBUG printk("read %d bytes,%d left\n",bytes_read,length); #endif return bytes_read; } static ssize_t device_write(struct file *file,char *buffer,size_t length,loff_t * offset) { int i; #ifdef DEBUG printk("device_write(%p,%s,%d)",file,buffer,length); #endif copy_from_user(Message,buffer,length); Message_Ptr = Message; return i; } static int device_open(struct inode * inode,struct file * file) { static int counter = 0; #ifdef DEBUG printk("device_open(%p,%p)\n",inode,file); #endif printk("Device:%d.%d\n",inode->i_rdev >> 8,inode->i_rdev & 0xFF); if(Device_Open) return -EBUSY; Device_Open++; sprintf(Message,"If I tole you once,I told you %d times - %s",counter++, "hello world\n"); Message_Ptr = Message; MOD_INC_USE_COUNT; return SUCCESS; } static int device_release(struct inode * inode,struct file *flie) { #ifdef DEBUG printk("device_release(%p,%p)\n",inode,file); #endif Device_Open--; MOD_DEC_USE_COUNT; return 0; } struct file_operations Fops = { read: device_read, write: device_write, open: device_open, release: device_release, }; int init_module(void) { Major = module_register_chrdev(0,DEVICE_NAME,&Fops); if(Major<0) { printk("%s device failed with %d\n","Sorry,registering the character", Major); return Major; } printk("%s the major device number is %d.\n","Registeration is a success.",Major); return 0; } void cleanup_module(void) { int ret; ret = module_unregister_chrdev(Major,DEVICE_NAME); if(ret<0) printk("error in unregister_chrdev :%d\n",ret); printk("exiting...\n"); } 存放在此目录下/home/atlantis/zqh/mydrv/,然后用如下命令编译 gcc -c mydrv.c -D_KERNEL_ -DMODULE -DLINUX -I/usr/src/linux-2.4.20-8/include 可是却出现了这么多错误,忘各位大哥指点一下 In file included from /usr/src/linux-2.4.20-8/include/linux/sched.h:16, from mydrv.c:3: /usr/src/linux-2.4.20-8/include/linux/timex.h:173: field `time' has incomplete type In file included from /usr/src/linux-2.4.20-8/include/linux/sched.h:23, from mydrv.c:3: /usr/src/linux-2.4.20-8/include/asm/mmu.h:12: field `sem' has incomplete type In file included from /usr/src/linux-2.4.20-8/include/linux/sched.h:31, from mydrv.c:3: /usr/src/linux-2.4.20-8/include/linux/pid.h:18: field `task_list' has incomplete type /usr/src/linux-2.4.20-8/include/linux/pid.h:19: field `hash_chain' has incomplete type /usr/src/linux-2.4.20-8/include/linux/pid.h:24: field `pid_chain' has incomplete type /usr/src/linux-2.4.20-8/include/linux/pid.h:36: parse error before '(' token /usr/src/linux-2.4.20-8/include/linux/pid.h:38: parse error before '(' token /usr/src/linux-2.4.20-8/include/linux/pid.h:43: parse error before '(' token /usr/src/linux-2.4.20-8/include/linux/pid.h:49: parse error before '(' token /usr/src/linux-2.4.20-8/include/linux/pid.h:52: parse error before '(' token In file included from mydrv.c:31: /usr/src/linux-2.4.20-8/include/asm/uaccess.h: In function `verify_area': /usr/src/linux-2.4.20-8/include/asm/uaccess.h:64: `current' undeclared (first use in this function) /usr/src/linux-2.4.20-8/include/asm/uaccess.h:64: (Each undeclared identifier is reported only once /usr/src/linux-2.4.20-8/include/asm/uaccess.h:64: for each function it appears in.) /usr/src/linux-2.4.20-8/include/asm/uaccess.h: In function `__constant_copy_to_user': /usr/src/linux-2.4.20-8/include/asm/uaccess.h:550: `current' undeclared (first use in this function) /usr/src/linux-2.4.20-8/include/asm/uaccess.h: In function `__constant_copy_from_user': /usr/src/linux-2.4.20-8/include/asm/uaccess.h:558: `current' undeclared (first use in this function) mydrv.c: At top level: mydrv.c:42: warning: `struct file' declared inside parameter list mydrv.c:42: warning: its scope is only this definition or declaration, which is probably not what you want mydrv.c: In function `device_read': mydrv.c:49: warning: passing arg 2 of `__constant_copy_to_user' makes pointer from integer without a cast mydrv.c:49: warning: passing arg 2 of `__generic_copy_to_user_Rd523fdd3' makes pointer from integer without a cast mydrv.c: At top level: mydrv.c:61: warning: `struct file' declared inside parameter list mydrv.c:76: warning: `struct file' declared inside parameter list mydrv.c:76: warning: `struct inode' declared inside parameter list mydrv.c: In function `device_open': mydrv.c:84: dereferencing pointer to incomplete type mydrv.c:84: dereferencing pointer to incomplete type mydrv.c: At top level: mydrv.c:103: warning: `struct file' declared inside parameter list mydrv.c:103: warning: `struct inode' declared inside parameter list mydrv.c:116: variable `Fops' has initializer but incomplete type mydrv.c:117: unknown field `read' specified in initializer mydrv.c:117: warning: excess elements in struct initializer mydrv.c:117: warning: (near initialization for `Fops') mydrv.c:118: unknown field `write' specified in initializer mydrv.c:118: warning: excess elements in struct initializer mydrv.c:118: warning: (near initialization for `Fops') mydrv.c:119: unknown field `open' specified in initializer mydrv.c:119: warning: excess elements in struct initializer mydrv.c:119: warning: (near initialization for `Fops') mydrv.c:120: unknown field `release' specified in initializer mydrv.c:120: warning: excess elements in struct initializer mydrv.c:120: warning: (near initialization for `Fops') mydrv.c:134:54: warning: multi-line string literals are deprecated mydrv.c:116: storage size of `Fops' isn't known Compilation exited abnormally with code 1 at Fri Sep 3 16:54:10 |
|