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>即可正常編譯產生模塊文件。