LDD3 范例程序在新版本Linux内核下的问题及解决办法

Linux内核从2.6.18到2 .6.19发生了较大变化,而《limux设备驱动程序3》中的程序是针对2.6.10内核的,在使用包含较新版本内核的linux发行版编译这些程序时,总不是向书上说的那么顺利,在此总结一下遇到的问题和解决办法,本篇日志会随着我的进度进行更新,有些问题可能发现了我也暂时解决不了,欢迎交流。

scull:
1)编译main.c时提示错误:main.c:17:26: error: linux/config.h: No such file or directory
解决办法:把#include<linux/config.h>注释掉或者在内核源码中创建空的config.h文件,从2.6.19后的新版本的内核已经不再包含config.h文件了,参见这里

2)编译access.c时提示错误:
/home/lits/test/access.c: In function ‘scull_u_open’:
/home/lits/test/access.c:108: error: dereferencing pointer to incomplete type
/home/lits/test/access.c:109: error: dereferencing pointer to incomplete type
/home/lits/test/access.c:116: error: dereferencing pointer to incomplete type
/home/lits/test/access.c: In function ‘scull_w_available’:
/home/lits/test/access.c:167: error: dereferencing pointer to incomplete type
/home/lits/test/access.c:168: error: dereferencing pointer to incomplete type
/home/lits/test/access.c: In function ‘scull_w_open’:
/home/lits/test/access.c:181: error: ‘TASK_INTERRUPTIBLE’ undeclared (first use in this function)
/home/lits/test/access.c:181: error: (Each undeclared identifier is reported only once
/home/lits/test/access.c:181: error: for each function it appears in.)
/home/lits/test/access.c:181: error: implicit declaration of function ‘signal_pending’
/home/lits/test/access.c:181: error: implicit declaration of function ‘schedule’
/home/lits/test/access.c:186: error: dereferencing pointer to incomplete type
/home/lits/test/access.c: In function ‘scull_w_release’:
/home/lits/test/access.c:207: error: ‘TASK_INTERRUPTIBLE’ undeclared (first use in this function)
/home/lits/test/access.c: In function ‘scull_c_open’:
/home/lits/test/access.c:279: error: dereferencing pointer to incomplete type
/home/lits/test/access.c:283: error: dereferencing pointer to incomplete type
/home/lits/test/access.c: In function ‘scull_access_setup’:
/home/lits/test/access.c:356: warning: format not a string literal and no format arguments
解决办法:在access.c中添加 #include <linux/sched.h>即可正常编译产生模块文件。

相关推荐