QQ登录

只需一步,快速开始

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 2738|回复: 2

编译一个最简单的驱动程序,出现了太多错误,不知所措,求救!

[复制链接]
发表于 2005-7-15 16:43:40 | 显示全部楼层 |阅读模式
编译一个最简单的驱动程序,出现了太多错误,不知所措,求救!

--------------------------------------------------------------------------------


在一本书上原抄了一个类似helloworld的驱动程序,TestDrive.c
shell下执行以下命令进行编译: gcc -O2 -DMODULE -D__KERNEL__ -c TestDriver.C
出现了这么多错误(比较长,请耐心点帮我看看,谢谢)

*********************以下是错误信息**************************
TestDriver.C:4:27: linux/modules.h: 没有那个文件或目录
In file included from /usr/include/linux/fs.h:18,
from TestDriver.C:9:
/usr/include/linux/list.h:37: parse error before `new'
/usr/include/linux/list.h: In function `void __list_add(...)':
/usr/include/linux/list.h:39: `next' undeclared (first use this function)
/usr/include/linux/list.h:39: (Each undeclared identifier is reported only once
for each function it appears in.)
/usr/include/linux/list.h:39: parse error before `;' token
/usr/include/linux/list.h:42: `prev' undeclared (first use this function)
/usr/include/linux/list.h:42: parse error before `;' token
/usr/include/linux/list.h: At global scope:
/usr/include/linux/list.h:53: parse error before `new'
/usr/include/linux/list.h: In function `void list_add(...)':
/usr/include/linux/list.h:55: parse error before `,' token
/usr/include/linux/list.h: At global scope:
/usr/include/linux/list.h:66: parse error before `new'
/usr/include/linux/list.h: In function `void list_add_tail(...)':
/usr/include/linux/list.h:68: parse error before `,' token
In file included from /usr/include/linux/fs.h:23,
from TestDriver.C:9:
/usr/include/linux/string.h:8:2: warning: #warning Using kernel header in userland!
In file included from /usr/include/linux/sched.h:14,
from /usr/include/linux/mm.h:4,
from TestDriver.C:10:
/usr/include/linux/timex.h: At global scope:
/usr/include/linux/timex.h:173: field `time' has incomplete type
In file included from /usr/include/linux/bitops.h:69,
from /usr/include/asm/system.h:7,
from /usr/include/linux/sched.h:16,
from /usr/include/linux/mm.h:4,
from TestDriver.C:10:
/usr/include/asm/bitops.h:327:2: warning: #warning This includefile is not available on all architectures.
/usr/include/asm/bitops.h:328:2: warning: #warning Using kernel headers in userspace: atomicity not guaranteed
In file included from /usr/include/linux/signal.h:4,
from /usr/include/linux/sched.h:25,
from /usr/include/linux/mm.h:4,
from TestDriver.C:10:
/usr/include/asm/signal.h:107: 'sigset_t' is used as a type, but is not defined
as a type.
In file included from /usr/include/linux/sched.h:81,
from /usr/include/linux/mm.h:4,
from TestDriver.C:10:
/usr/include/linux/timer.h:45: 'spinlock_t' is used as a type, but is not
defined as a type.
TestDriver.C:18: variable `file_operations tdd_fops' has initializer but
incomplete type
TestDriver.C:41: `BUF_LEN' was not declared in this scope
TestDriver.C: In function `int device_open(inode*, file*)':
TestDriver.C:53: `MOD_INC_USE_COUNT' undeclared (first use this function)
TestDriver.C: In function `void device_release(inode*, file*)':
TestDriver.C:65: `MOD_DEC_USE_COUNT' undeclared (first use this function)
TestDriver.C: In function `int device_read(inode*, file*, char*, int)':
TestDriver.C:71: `VERIFY_WRITE' undeclared (first use this function)
TestDriver.C:71: `verify_area' undeclared (first use this function)
TestDriver.C:75: `_put_user' undeclared (first use this function)
TestDriver.C: In function `int init_module()':
TestDriver.C:86: `register_chrdev' undeclared (first use this function)
TestDriver.C:88: `KERN_INFO' undeclared (first use this function)
TestDriver.C:88: `printk' undeclared (first use this function)
TestDriver.C: In function `void cleanup_module()':
TestDriver.C:101: `unregister_chrdev' undeclared (first use this function)
TestDriver.C: At global scope:
TestDriver.C:18: storage size of `tdd_fops' isn't known
***************************************************************
我的头文件是这样的:

****************以下是TestDriver.c程序的开头部分**********************
/*TestDriver.c*/
/*一个简单的字符设备驱动实例*/
#define __NO_VERSION__
#include <linux/modules.h>
#include <linux/version.h>
char kernel_version [] = UTS_RELEASE;
#define KERNEL
#include <linux/types.h>
#include <linux/fs.h>
#include <linux/mm.h>
#include <linux/errno.h>
#include <asm/segment.h>
****************************************************************

从出错信息中可以看到,/usr/include/linux/下面有很多.h文件都有错误,可是那都是系统自带的阿,我绝对没有改过,我装的是redhat9.0系统,内核版本是2.4.20-8

后面还有一些出错信息比如printk/register_chrdev/MOD_INC_USE_COUNT........没有定义,但我看了很多
驱动的例子,也特意包含了他们的所有头文件阿,

这只是一个最简单的例子,就有这么多问题,我要完成编写一个芯片可用驱动的任务痛苦+没有信心中...

谁能帮我指点一下,到底该怎么解决这么多错误?

谢谢!
发表于 2005-7-19 11:30:30 | 显示全部楼层
你用的内核版本是2.4的还是2.6的??
如果2.4的kernel 那么linux/modules.h本来就不存在!!
ls /usr/include/`uname -r`/include/linux/modules.h
没有那个文件或目录
2.4的只有<linux/module.h>
另外头文件最好用GCC的 -I 选项指定!
回复

使用道具 举报

发表于 2005-7-19 18:19:34 | 显示全部楼层
应该有-I/usr/src/linux-*.*.*/include
回复

使用道具 举报

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

本版积分规则

GMT+8, 2024-11-16 12:42 , Processed in 0.053168 second(s), 16 queries .

© 2021 Powered by Discuz! X3.5.

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