编译驱动scull出错后解决方案

编译驱动scull出错后解决方案

1、scripts/Makefile.build:49: *** CFLAGS was changed in "/home/robin/drivers/scull/Makefile". Fix it to use EXTRA_CFLAGS.  Stop.

将makefile中的 CFLAGS 替换成 EXTRA_CFLAGS就可以了。

原因是在2.6的内核的版本中所有的 EXTRA_ 变量只在所定义的Kbuild Makefile中起作用。EXTRA_ 变量可    以在Kbuild Makefile中所有命令中使用。    $(EXTRA_CFLAGS) 是用 $(CC) 编译C源文件时的选项。   

2、error: 'TASK_INTERRUPTIBLE' undeclared (first use in this function)

错误定位行,原因缺少头文件 #include <linux/sched.h> 添加后即可通过编译 !微笑


3、scull:
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文件了,

4、/home/robin/drivers/scull/access.c: In function ‘scull_w_available’:
/home/robin/drivers/scull/access.c:165: error: ‘struct task_struct’ has no member named ‘uid’
/home/robin/drivers/scull/access.c:166: error: ‘struct task_struct’ has no member named ‘euid’
/home/robin/drivers/scull/access.c: In function ‘scull_w_open’:
/home/robin/drivers/scull/access.c:184: error: ‘struct task_struct’ has no member named ‘uid’

根据提示,错误在于task_struct结构体没有uid,euid成员变量,查看源码发现struct task_struct定义在include/linux/sched.h中,确实没有这两个成员,逐个成员分析发现,这两个成员在2.6.35内核中放在const struct cred *cred成员中了,所以,我们尝试将所有出现错误的地方做如下改动:

current->uid 修改为 current->cred->uid

current->euid 修改为 current->cred->euid

接着make,发现成功编译。

你可能感兴趣的:(c,function,struct,File,makefile)