LDD3学习笔记scull编译错误解决

本文针对在编译Linux内核模块过程中遇到的多种典型错误进行了详细解析,并提供了有效的修正方法,包括修改Makefile配置、注释或替换过时的头文件引用、调整函数声明及参数类型等。

1、./scripts/Makefile.build:49: *** CFLAGS was changed in "/home/jerry/luo/module/examples/scull/Makefile". Fix it to use ccflags-y.

很明确了。直接将Makefile的CFLAGS改成ccflags-y。

2、 fatal error: linux/config.h: No such file or directory 

#include <linux/config.h>

直接注释掉。

3、fatal error: asm/system.h: No such file or directory

#include <asm/system.h>  /* cli(), *_flags */

     3.3以后的内核用switch_to.h 替代了 system.h

4、 error: unknown field ‘ioctl’ specified in initializer
  .ioctl =    scull_ioctl,

原先的

   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);

5、implicit declaration of function ‘init_MUTEX’ [-Werror=implicit-function-declaration]
   init_MUTEX(&scull_devices[i].sem);

3.x内核以后用sema_init(xxxxxx);

6、‘TASK_INTERRUPTIBLE’ undeclared (first use in this function) 

未定义,那就添加定义该符号的头文件咯
#include <linux/sched.h>
7、error: ‘SPIN_LOCK_UNLOCKED’ undeclared here (not in a function)

改为static DEFINE_SPINLOCK(scull_u_lock);

8、error: ‘struct task_struct’ has no member named ‘uid’

      error: ‘struct task_struct’ has no member named ‘euid’

加头文件cred.h,将 current->uid改为current->cred->uid,current->euid改为current->cred->euid

9、error: invalid operands to binary != (have ‘uid_t’ and ‘kuid_t’)

      error: incompatible types when assigning to type ‘uid_t’ from type ‘kuid_t’

首先是类型不匹配。kuid_t类型:

typedef struct {

uid_t val;

} kuid_t;

改为current->cred->uid.val;

current->cred->euid.val;

剩下还会报一些警告,是因为unclocked_ioctl与ioctl的指针指向的类型不太一样。改一下就好了。




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值