调用class_create(),class_device_create()函数编译报错的解决方法
来源:互联网 发布:混凝土强度试验数据 编辑:程序博客网 时间:2024/06/02 05:10
在代码中加入class_create(),class_device_create()函数,编译时华丽丽得报了一大堆错误:
make -C /usr/src/linux-source-4.4.0 M=/home/ubuntu/Documents/first_drv modules make[1]: Entering directory '/usr/src/linux-source-4.4.0' CC [M] /home/ubuntu/Documents/first_drv/firstdrv.o/home/ubuntu/Documents/first_drv/firstdrv.c: In function ‘first_drv_init’:/home/ubuntu/Documents/first_drv/firstdrv.c:50:23: error: implicit declaration of function ‘class_device_create’ [-Werror=implicit-function-declaration] firstdrv_class_dev = class_device_create(firstdrv_class, NULL, MKDEV(major, 0) ^/home/ubuntu/Documents/first_drv/firstdrv.c:50:21: warning: assignment makes pointer from integer without a cast [-Wint-conversion] firstdrv_class_dev = class_device_create(firstdrv_class, NULL, MKDEV(major, 0) ^/home/ubuntu/Documents/first_drv/firstdrv.c: In function ‘first_drv_exit’:/home/ubuntu/Documents/first_drv/firstdrv.c:62:2: error: implicit declaration of function ‘class_device_unregister’ [-Werror=implicit-function-declaration] class_device_unregister(firstdrv_class_dev); ^cc1: some warnings being treated as errorsscripts/Makefile.build:264: recipe for target '/home/ubuntu/Documents/first_drv/firstdrv.o' failedmake[2]: *** [/home/ubuntu/Documents/first_drv/firstdrv.o] Error 1Makefile:1420: recipe for target '_module_/home/ubuntu/Documents/first_drv' failedmake[1]: *** [_module_/home/ubuntu/Documents/first_drv] Error 2make[1]: Leaving directory '/usr/src/linux-source-4.4.0'Makefile:19: recipe for target 'all' failedmake: *** [all] Error 2
网上搜索后发现是Linux内核版本不同的原因!早期的版本,使用的是上面说的两个函数,但是在2.6.29以后,使用的函数则变成了 class_create()和device_create(),并且要在声明中加入
#include <linux/device.h>
因为定义这些函数是在linux4.4.0/include/linux/device.h里面!
在first_drv_init()和first_drv_exit()函数中把class_device_create()、
class_device_unregister()函数修改为device_create()和device_unregister()后,error消失了,但还是有如下warning:
/home/ubuntu/Documents/first_drv/firstdrv.c:50:21: warning: assignment from incompatible pointer type [-Wincompatible-pointer-types] firstdrv_class_dev = device_create(firstdrv_class, NULL, MKDEV(major, 0), NULL ^/home/ubuntu/Documents/first_drv/firstdrv.c: In function ‘first_drv_exit’:/home/ubuntu/Documents/first_drv/firstdrv.c:62:20: warning: passing argument 1 of ‘device_unregister’ from incompatible pointer type [-Wincompatible-pointer-types] device_unregister(firstdrv_class_dev); ^In file included from /home/ubuntu/Documents/first_drv/firstdrv.c:6:0:include/linux/device.h:988:13: note: expected ‘struct device *’ but argument is of type ‘struct class_device *’ extern void device_unregister(struct device *dev); ^ Building modules, stage 2. MODPOST 1 modules CC /home/ubuntu/Documents/first_drv/firstdrv.mod.o LD [M] /home/ubuntu/Documents/first_drv/firstdrv.komake[1]: Leaving directory '/usr/src/linux-source-4.4.0'
原因是
static struct class_device *firstdrv_class_dev;
这个结构体指针变量的声明也要进行修改,改为
static struct device *firstdrv_class_dev;
完成上述修改后,编译ok啦
阅读全文
0 0
- 调用class_create(),class_device_create()函数编译报错的解决方法
- class_create() class_device_create
- class_create & class_device_create
- class_create和class_device_create
- cvQueryHistValue_1D函数编译报错的解决方法
- class_create(),class_device_create()创建/dev/xxx 名字
- class_create(),class_device_create()创建/dev/xxx 名字
- class_create(),class_device_create()创建/dev/xxx 名字
- Swift工程调用含有FMDB的Framework编译报错的解决方法
- android4.0 编译报错的解决方法
- android4.1 编译报错的解决方法
- class_create()函数
- class_create(),class_device_create()或device_create()自动创建设备文件结点
- class_create(),class_device_create()或device_create()自动创建设备文件结点
- class_create(),class_device_create()或device_create()自动创建设备文件结点
- class_create(),class_device_create()或device_create()自动创建设备文件结点
- class_create(),class_device_create()或device_create()自动创建设备文件结点
- class_create(),class_device_create()或device_create()自动创建设备文件结点
- JDK内存管理工具收集
- gradle插件buildship
- 模仿HttpSession自定义Session并且使用Redis支持共享,能完美接入负载均衡
- 机器学习实战(1)
- 1.6 spring 4.3.10 JAR 官网下载
- 调用class_create(),class_device_create()函数编译报错的解决方法
- Android插件化基础篇 — dex 文件
- 共享单车重新定义了“地铁房”?
- Android——区别DVM与JVM
- [RK3288][Android6.0] 调试笔记 --- 恢复出厂设置掉电保护
- opencv开发笔记(六):鼠标操作回调函数的使用
- Go报错 : syntax error: unexpected string, expecting comma or )
- 关于实信号的双边谱和单边谱
- POJ3349-Snowflake Snow Snowflakes(hash表)