边干边学 linux内核指导,《边干边学-Linux内核指导》这本书上的那个“设计自己的驱动程序”的例子拿来编译不知道为什么错???...

(源代码见下面)

书上说:采用下面的命令对vfifo.c进行编译:

#gcc -c vfifo.c -D_KERNEL__ -DMODULE -O2 -g -Wall

如果没有出错的话,将会在本目录下生成一个vfifo.o文件。

可是我在redhat 9上编译出错,错误如下:

In file included from /usr/include/linux/fs.h:23,

from vfifo.c:17:

/usr/include/linux/string.h:8:2: warning: #warning Using kernel header in userland!

In file included from vfifo.c:18:

/usr/include/linux/proc_fs.h:70: parse error before "atomic_t"

/usr/include/linux/proc_fs.h:73: parse error before '}' token

/usr/include/linux/proc_fs.h:203: parse error before "void"

In file included from /usr/include/linux/bitops.h:69,

from /usr/include/asm/system.h:7,

from vfifo.c:25:

/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

vfifo.c:27:25: asm/uaccess.h: 没有那个文件或目录

In file included from /usr/include/linux/sched.h:14,

from /usr/include/linux/mm.h:4,

from /usr/include/linux/locks.h:5,

from /usr/include/linux/devfs_fs_kernel.h:6,

from vfifo.c:41:

/usr/include/linux/timex.h:173: field `time' has incomplete type

/usr/include/linux/timex.h:188: confused by earlier errors, bailing out

在Fedora 6上试了也不行。

小弟经验不足,希望能得到大家的指点。

|

楼主你安装内核的头文件了吗?驱动程序必须依赖这些的啊,你看我的目录:

[root][~]# ls -al /usr/src/

total 24

drwxrwsr-x  6 root src  4096 2009-02-26 07:43 .

drwxr-xr-x 11 root root 4096 2009-02-26 07:22 ..

drwxr-xr-x  3 root root 4096 2009-02-26 07:43 glibc

drwxr-xr-x  4 root root 4096 2009-02-26 07:40 linux-headers-2.6.26-1-686

drwxr-xr-x 18 root root 4096 2009-02-26 07:40 linux-headers-2.6.26-1-common

drwxr-xr-x  3 root root 4096 2009-02-26 07:40 linux-kbuild-2.6.26

|

#gcc -c vfifo.c -D_KERNEL__ -DMODULE -O2 -g -Wall

你这里的宏少了个下划线,所以才会提示warning: #warning Using kernel header in userland!。是-D__KERNEL__,而不是-D_KERNEL__

这是一个错误,先更正了再看有没有其他问题

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
第1章 了解Linux内核 1. 1 Linux内核 1. 2 查看Linux内核状况 1. 3 编程序检查系统状况 1. 4 Linux编程环境 第2章 shell 2. 1 she11 2. 2 实现一个简单的shell程序 2. 3 shell编程 第3章 内核时钟 3. 1 关于时钟和定时器 3. 2 Linux系统时钟 3. 3 Linux系统定时器 3. 4 时钟命令介绍 3. 5 定时器的应用 第4章 内核模块 4. 1 概述 4. 2 模块实现机制 4. 3 实例 第5章 系统调用 5. 1 一个简单的例子 5. 2 系统调用基础知识 5. 3 相关数据结构. 源代码分析及流程 5. 4 详细讲解一个系统调用的实现 5. 5 简单系统调用的添加 5. 6 较高级主题:添加一个更复杂的系统调用 第6章 共享内存 6. 1 进程间通信和共享内存 6. 2 共享内存的APl 6. 3 实现共享内存的源代码 6. 4 利用共享内存进行进程间通信 第7章 虚拟存储 7. 1 虚拟内存管理 7. 2 Linux虚拟内存管理 7. 3 实例 第8章 进程的同步 8. 1 同步机制 8. 2 Linux中几种同步机制的实现 8. 3 设计我们自己的同步机制 第9章 进程调度 9. 1 进程调度简介 9. 2 进程调度的策略与算法 9. 3 进程调度的实现 9. 4 改进进程调度算法的实现 第10章 设备驱动 lo. 1 Linux驱动程序的相关概念 10. 2 传统的设备管理方式 10. 3 块设备的请求队列 lo. 4 设备文件系统devfs 10. 5 驱动程序的框架及实例分析 10. 6 设计自己的驱动程序 第11章 文件系统 11. 1 文件和目录 11. 2 文件系统的框架 11. 3 VFS文件系统 11. 4 ext2文件系统 11. 5 open. Close和read. write操作 11. 6 buffer cache 11. 7 实验:添加一个文件系统 11. 8 附录:优秀的日志文件系统--ext3

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值