赞
踩
LDD3中的第一个例程就是scull,但是在新内核上编译的过程那叫一个坎坷。。。 在此做出总结,希望可以帮到同路人。。。
一、错误:
error: linux/config.h:
No such file or directory
解决: 从linux-2.6.20起,config.h就已经被移除了. 在main.c中, 将#include 改为:
#include
#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,18))
#include
#endif
二、错误:
/ldd3_examples/scull/main.c:32:46: fatal error: asm/system.h: No
such file or directory
解决: 在main.c中, 将#include 改为:
#if LINUX_VERSION_CODE > KERNEL_VERSION(3,3,0)
#include
#else
#include
#endif
在目录:/usr/src/linux-headers-3.11.0-15/include下没有asm,只有asm-generic,执行ln
-s asm-generic asm可以解决。
三、错误:
error: implicit
declaration of function ‘init_MUTEX’
[-Werror=implicit-function-declaration]
解决: 在新版本的linux内核中,init_mutex已经被废除了,新版本使用sema_init函数。需要在main.c中包含头文件#include
将init_MUTEX(&scull_devices[i].sem); 改为:sema_init(&scull_devices[i].sem,1);
四、错误:
error: unknown field ‘ioctl’ specified in initializer
解决:
原因是:在2.6.36内核上file_operations发生了重大的改变: 原先的 int (ioctl)(struct inode, struct file*, unsigned int,
unsigned long); 被改为了 long (unlocked_ioctl) (struct file,
unsigned int, unsigned long); long (compat_ioctl) (struct file,
unsigned int, unsigned long);
因而在实际驱动中,我们需要将原先的写的ioctl函数头给改成下面的unlocked_ioctl,在file_operations结构体的填充中也是一样。
五、错误: /home/jassion/work/book/ldd3_examples/scull/pipe.c: In function
‘scull_p_read’: /home/jassion/work/book/ldd3_examples/scull/pipe.c:131:7: error:
‘TASK_INTERRUPTIBLE’ undeclared (first use in this
function) /home/jassion/work/book/ldd3_examples/scull/pipe.c:131:7: note:
each undeclared identifier is reported only once for each function
it appears in /home/jassion/work/book/ldd3_examples/scull/pipe.c:131:3: error:
implicit declaration of function ‘signal_pending’
[-Werror=implicit-function-declaration] /home/jassion/work/book/ldd3_examples/scull/pipe.c:131:3: error:
implicit declaration of function ‘schedule’
[-Werror=implicit-function-declaration] /home/jassion/work/book/ldd3_examples/scull/pipe.c: In function
‘scull_getwritespace’: /home/jassion/work/book/ldd3_examples/scull/pipe.c:168:38: error:
‘TASK_INTERRUPTIBLE’ undeclared (first use in this
function) /home/jassion/work/book/ldd3_examples/scull/pipe.c: In function
‘scull_p_write’: /home/jassion/work/book/ldd3_examples/scull/pipe.c:219:2: error:
‘TASK_INTERRUPTIBLE’ undeclared (first use in this
function) /home/jassion/work/book/ldd3_examples/scull/pipe.c:223:34: error:
‘SIGIO’ undeclared (first use in this
function) /home/jassion/work/book/ldd3_examples/scull/pipe.c:223:41: error:
‘POLL_IN’ undeclared (first use in this function)
解决: 头文件变动原因,在pipe.c中添加
#include
六、错误: /home/jassion/work/book/ldd3_examples/scull/pipe.c:321:2: error:
unknown field ‘ioctl’ specified in
initializer 解决: 在pipe.c中, 将.ioctl = scull_ioctl, 改为.unlocked_ioctl = scull_ioctl,
七、错误: /home/jassion/work/book/ldd3_examples/scull/pipe.c: In function
‘scull_p_init’: /home/jassion/work/book/ldd3_examples/scull/pipe.c:367:3: error:
implicit declaration of function ‘init_MUTEX’
[-Werror=implicit-function-declaration]
解决: 在pipe.c中, 将init_MUTEX(&scull_p_devices[i].sem); 改为:sema_init(&scull_p_devices[i].sem,1);
八、错误: access.c中的一系列错误 1、/home/jassion/work/book/ldd3_examples/scull/access.c:98:34:
error: ‘SPIN_LOCK_UNLOCKED’ undeclared here (not in a function)
解决:原因,SPIN_LOCK_UNLOCKED在新内核中被弃用 在access.c中添加头文件:
#include
修改定义 static spinlock_t scull_u_lock =
SPIN_LOCK_UNLOCKED; 为:static DEFINE_SPINLOCK(scull_u_lock);
2、/home/jassion/work/book/ldd3_examples/scull/access.c:179:3:
error: implicit declaration of function ‘signal_pending’
[-Werror=implicit-function-declaration] /home/jassion/work/book/ldd3_examples/scull/access.c:179:3: error:
implicit declaration of function ‘schedule’
[-Werror=implicit-function-declaration]。。。。。。。
解决: 在access.c中添加头文件:
#include
3、/home/jassion/work/book/ldd3_examples/scull/access.c: In function
‘scull_u_open’: /home/jassion/work/book/ldd3_examples/scull/access.c:108:29: error:
‘struct task_struct’ has no member named
‘uid’ /home/jassion/work/book/ldd3_examples/scull/access.c:109:29: error:
‘struct task_struct’ has no member named
‘euid’ /home/jassion/work/book/ldd3_examples/scull/access.c:116:26: error:
‘struct task_struct’ has no member named
‘uid’ 。。。。。。
解决:原因:新的struct
task_struct 定义有变化,uid和euid在cred结构体中。 办法:加头文件#include , 将
current->uid改为current->cred->uid, current->euid改为current->cred->euid
其他的问题,参考上面的方法进行处理即可。
编译成功之后的截图:
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。