LinuxSir.cn,穿越时空的Linuxsir!

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

模块编译出错求救

[复制链接]
发表于 2005-3-23 22:58:03 | 显示全部楼层 |阅读模式
各位大虾
这是我便以后出现的错误,我感到很困惑,不知怎么改,感觉与系统有关
我使用的是FC2,请各位帮忙看看
以下是错误信息:
[root@paul c]# gcc -O2 -DMODULE -D__KERNEL__ -c chardev.c
In file included from /usr/include/linux/module.h:10,
                 from chardev.c:2:
/usr/include/linux/config.h:5:2: #error Incorrectly using glibc headers for a kernel module
chardev.c:13:24: asm/uaccess.h:没有此目录
chardev.c:19: warning: `struct file' declared inside parameter list
chardev.c:19: warning: its scope is only this definition or declaration, which is probably not what you want
chardev.c:35: warning: `struct file' declared inside parameter list
chardev.c:46: warning: `struct file' declared inside parameter list
chardev.c:46: warning: `struct inode' declared inside parameter list
chardev.c: In function `open_test':
chardev.c:48: error: `__this_module' undeclared (first use in this function)
chardev.c:48: error: (Each undeclared identifier is reported only once
chardev.c:48: error: for each function it appears in.)
chardev.c: At top level:
chardev.c:51: warning: `struct file' declared inside parameter list
chardev.c:51: warning: `struct inode' declared inside parameter list
chardev.c: In function `release_test':
chardev.c:53: error: `__this_module' undeclared (first use in this function)
chardev.c: At top level:
chardev.c:58: error: variable `test_fops' has initializer but incomplete type
chardev.c:59: warning: excess elements in struct initializer
chardev.c:59: warning: (near initialization for `test_fops')
chardev.c:60: warning: excess elements in struct initializer
chardev.c:60: warning: (near initialization for `test_fops')
chardev.c:61: warning: excess elements in struct initializer
chardev.c:61: warning: (near initialization for `test_fops')
chardev.c:62: warning: excess elements in struct initializer
chardev.c:62: warning: (near initialization for `test_fops')
chardev.c:63: warning: excess elements in struct initializer
chardev.c:63: warning: (near initialization for `test_fops')
chardev.c:64: warning: excess elements in struct initializer
chardev.c:64: warning: (near initialization for `test_fops')
chardev.c:65: warning: excess elements in struct initializer
chardev.c:65: warning: (near initialization for `test_fops')
chardev.c:66: warning: excess elements in struct initializer
chardev.c:66: warning: (near initialization for `test_fops')
chardev.c:67: warning: excess elements in struct initializer
chardev.c:67: warning: (near initialization for `test_fops')
chardev.c:68: warning: excess elements in struct initializer
chardev.c:68: warning: (near initialization for `test_fops')
chardev.c:69: warning: excess elements in struct initializer
chardev.c:69: warning: (near initialization for `test_fops')
chardev.c:70: warning: excess elements in struct initializer
chardev.c:70: warning: (near initialization for `test_fops')
chardev.c:58: error: storage size of `test_fops' isn't known


第一:
chardev.c:13:24: asm/uaccess.h:没有此目录
我看了好多模块驱动程序,都要加这个文件,为什么这里加上去反而出错?
第二:
chardev.c:53: error: `__this_module' undeclared (first use in this function)
怎么会没申明 ?
第三:
chardev.c:58: error: variable `test_fops' has initializer but incomplete type
这个错误是怎么回事?

源代码:
#define __NO_VERSION__
#include<linux/version.h>
#include<linux/module.h>
#include<linux/config.h>
#include<linux/kernel.h>
#include<linux/fs.h>
#include<linux/types.h>
#include <asm/system.h>
#include <linux/errno.h>
#include <asm/segment.h>
#include<asm/uaccess.h>

unsigned int test_major = 0;
char mem[10];


static ssize_t read_test(struct file *file,char *buffer,size_t length,loff_t *offset) /* 文件偏移量 */
{

int left;

for(left = length ; left > 0 ; left--)
{
__put_user(mem
, buffer++);
}
return length;
}


static ssize_t write_test(struct file *file,
const char *buffer, /* 缓冲区 */
size_t length, /* 缓冲区长度 */
loff_t *offset) /* 文件偏移量 */
{
int left;

for(left = length ; left > 0 ; left--)
{
get_user(buffer++,mem
);
}
return length;
}

static int open_test(struct inode *inode,struct file *file )
{
int i;
for(i=0;i<10;i++)
{
  mem=i;
}
MOD_INC_USE_COUNT;
return 0;
}
static int release_test(struct inode *inode,struct file *file )
{
MOD_DEC_USE_COUNT;
return 0;
}


struct file_operations test_fops = {   /*设备操作函数*/
NULL,
read_test,
write_test,
NULL, /* test_readdir */
NULL, /* test_ioctl */
NULL, /* test_mmap */
open_test,
NULL,
release_test,
NULL,
NULL,
NULL,
};

int init_module(void)
{
int result;
result = register_chrdev(0, "test", &test_fops); /*注册设备,返回设备号*/
if (result < 0) {
printk("test: can't get major number!\n");
return result;
}
if (test_major == 0) test_major = result; /* dynamic 设备号*/
printk("Insmod successfully!\n");
return 0;
}

void cleanup_module(void)
{
unregister_chrdev(test_major, "test");  /*注销设备*/
printk("Rmmod successfully!\n");
}
发表于 2005-3-25 20:31:00 | 显示全部楼层
你直接用gcc编译,头文件目录不用指出来吗?
回复 支持 反对

使用道具 举报

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

本版积分规则

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