内存分配模块编译出错

来源:互联网 发布:网上发布软件 编辑:程序博客网 时间:2024/05/16 16:06

编译模块时,出现以下问题

/home/alloc_mem.c:13: warning: function declaration isn't a prototype
/home/alloc_mem.c: In function 'alloc_init':
/home/alloc_mem.c:14: error: implicit declaration of function'kmalloc'
/home/alloc_mem.c:14: warning: assignment makes pointer from integer without a cast
/home/alloc_mem.c:19: warning: assignment makes pointer from integer without a cast
/home/alloc_mem.c: At top level:
/home/alloc_mem.c:25: warning: function declaration isn't a prototype
/home/alloc_mem.c: In function 'alloc_exit':
/home/alloc_mem.c:26: error: implicit declaration of function 'kfree'
/home/alloc_mem.c:27: warning: passing argument 1 of 'free_pages' makes integer from pointer without a cast
make[2]: *** [/home/shiyan/4-4-1/neicun/alloc_mem.o] Error 1
make[1]: *** [_module_/home/shiyan/4-4-1/neicun] Error 2
make[1]: Leaving directory `/home/shiyan/neihe/linux-2.6.36.2-v1.05'
make: *** [all] Error 2

在网上找了一下,是缺少了一个头文件#include <linux/slab.h>加上之后就没问题了,另外还有驱动的加载函数还有卸载函数也要在括号中注意加上void,避免一些不必要的错误

 

 

1.在编译内核时 出现drivers/char/memdev.c:174: error: implicit declaration of function'kmalloc'
在网上找了下原来是少了头文件#include<linux/slab.h>。

2.app-mem.c:9: warning: incompatible implicit declaration of built-in function 'strcpy'
原因是缺少头文件#include<string.h>。
 
 /home/shiyan/5-1-1CQD/ioctlqudong/memdev.c:84: error: unknown field 'ioctl'specified in initializer

在linux-2.6.36内核上加载编译驱动时,出现

 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结构体的填充中也是一样。

原创粉丝点击