initialization from incompatible pointer type [-Werror=incompatible-pointer-types]

在linux上make出现一下报错:

/mnt/hgfs/share/memoryShare/mmap3.c:82:17: error: initialization from incompatible pointer type [-Werror=incompatible-pointer-types]
        .fault = &tmmapnopage_fault,//mmapnopage_vm_fault,
                 ^
/mnt/hgfs/share/memoryShare/mmap3.c:82:17: note: (near initialization for ‘mmapnopage_vm_ops.fault’)

initialization from incompatible pointer type [-Werror=incompatible-pointer-types]意思是指针类型不兼容。

出错位置:

struct vm_operations_struct mmapnopage_vm_ops={
       .fault = tmmapnopage_fault,
};

其中,tmmapnopage_fault函数的原型为

vm_fault_t  tmmapnopage_fault(struct vm_fault *vmf)

再进入linux内核源码查看vm_operations_struct结构的.fault原型:

首先,键入命令:

cd /usr/src/内核版本/include/linux

(内核版本可由 uname -r命令获得)

然后,通过vi编辑器查看mm.h头文件:
vi mm.h

initialization from incompatible pointer type [-Werror=incompatible-pointer-types]_第1张图片

对比.faulttmmapnopage_fault的函数原型,可得到前者有俩参数而后者只有一个。

故对后者再添加一个参数,使两者函数原型相同

修改为:

vm_fault_t  tmmapnopage_fault(struct vm_area_struct *vma,struct vm_fault *vmf)
 

你可能感兴趣的:(linux)