Posted on 2013-04-02 15:36
墨…… 閱讀(912)
評論(0) 編輯 收藏 引用
編譯 scull
出現以下錯誤
Fix it to use ccflags-y. Stop.
將 Makefile 中的 CFLAGS 改為 ccflags-y, 重新 make,又出現錯誤
main.c:15:26: fatal error: linux/config.h: No such file or directory
將 main.c 中的 #include <linux/config.h> 刪除或注釋掉,重新 make,繼續編譯會遇到如下問題
main.c:634:2: error: unknown field 'ioctl' specified in initializer
是因為內核中的 file_operations 結構發生了改變,將 main.c 中 scull_fops 聲明處的 .ioctl 改為 .unlocked_ioctl 即可,繼續編譯還會遇到如下問題
main.c:652:3: error: implicit declaration of function ‘init_MUTEX’ [-Werror=implicit-function-declaration]
可在 main.c 的開始處添加以下代碼解決問題
#include <linux/semaphore.h>
#define init_MUTEX(a) sema_init(a,1)
#define init_MUTEX_LOCKED(a) sema_init(a,0)
到這時還沒完,我開始有點煩燥了...繼續前進時還出現以下錯誤
pipe.c: In function ‘scull_p_read’:
pipe.c:131:7: error: ‘TASK_INTERRUPTIBLE’ undeclared (first use in this function)
pipe.c:131:7: note: each undeclared identifier is reported only once for each function it appears in
pipe.c:131:3: error: implicit declaration of function ‘signal_pending’ [-Werror=implicit-function-declaration]
pipe.c:131:3: error: implicit declaration of function ‘schedule’ [-Werror=implicit-function-declaration]
該問題可向 pipe.c 和 access.c 中添加
#include <linux/sched.h> 來解決,但后面還會遇到這樣的問題
access.c:101:34: error: ‘SPIN_LOCK_UNLOCKED’ undeclared here (not in a function)
在access.c文件中用 static DEFINE_SPINLOCK(scull_w_lock); 來代替 static spinlock_t scull_w_lock = SPIN_LOCK_UNLOCKED;
繼續進行,遭遇下面問題
access.c:111:29: error: ‘struct task_struct’ has no member named ‘uid’
access.c:112:29: error: ‘struct task_struct’ has no member named ‘euid’
access.c:119:26: error: ‘struct task_struct’ has no member named ‘uid’
把 access.c 文件中的
current->uid
current->euid
全部修對應地改為
current->cred->uid
current->cred->euid
繼續重新 make,終于可以生成 scull.ko 了,OMG......
還要注意的是,上面的錯誤可能不止發生在一個地方,編譯時需要注意看清錯誤提示,如果有跟上面一樣的錯誤發生,只需參照上面的方法來修改即可。
驅動不會在虛擬終端上輸出,所以如果在終端上沒看到驅動的輸出,可以看看是不是輸出到日志中了:/var/log/syslog
Contact us