implicit declaration of function 'class_device_create'

本文探讨了在内核驱动编译过程中遇到的隐式函数声明错误,介绍了如何通过查看内核源代码来确定使用正确的函数名,并提供了实际案例演示。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

implicit declaration of function 'class_device_create'

 

编译内核驱动时经常会出现这样的错误:implicit declaration of function 'class_device_create'或者是implicit declaration of function 'class_device_destroy'

implicit <wbr>declaration <wbr>of <wbr>function <wbr>'class_device_create'

这种错误我以前也有提到过,只要把'class_device_create'改成'device_create','class_device_destroy'改成'device_destroy'一般就可以正确通过编译了。这主要是由内核版本决定的,那么我们怎样看一个内核到底是支持'class_device_create'还是'device_create',每次都这样尝试可能有点麻烦。

 

我们可以通过查看implicit <wbr>declaration <wbr>of <wbr>function <wbr>'class_device_create'

路径下的device.h文件来看到底是支持哪个的。

下面是2.6.30内核的关于'device_create'的声明

implicit <wbr>declaration <wbr>of <wbr>function <wbr>'class_device_create'

如果内核声明的是'class_device_create',那么编写内核的时候就改成'class_device_create'就可以了。

以下为我编写的内核模块和makefile文件:#include <linux/init.h> //所有模块都会需要这个头文件 #include <linux/module.h> //下面的宏需要 static int __init hello_init(void){ printk(KERN_INFO "module init success\n"); return 0; } static void __exit hello_exit(void){ printk(KERN_INFO "module exit success\n"); } module_init(hello_init); module_exit(hello_exit); MODULE_LICENSE("GPL"); //开源协议 MODULE_AUTHOR("作者"); MODULE_DESCRIPTION("功能描述"); obj-m := hello.o PWD := $(shell pwd) KVER := $(shell uname -r) KDIR :=/lib/modules/$(KVER)/build/ all: $(MAKE) -C $(KDIR) M=$(PWD) clean: rm -rf *.o *.mod.c *.mod.o *.ko *.symvers *.order *.a——运行时出现以下报错,请问怎么解决:linzihao@linzihao-virtual-machine:~/Code/test/coursework2/work3$ make make -C /lib/modules/4.15.0-213-generic/build M=/home/linzihao/Code/test/coursework2/work3 modules make[1]: 进入目录“/usr/src/linux-headers-4.15.0-213-generic” CC [M] /home/linzihao/Code/test/coursework2/work3/my_char_dev.o /home/linzihao/Code/test/coursework2/work3/my_char_dev.c: In function ‘dev_write’: /home/linzihao/Code/test/coursework2/work3/my_char_dev.c:20:12: error: implicit declaration of function ‘kmalloc’; did you mean ‘vmalloc’? [-Werror=implicit-function-declaration] kbuf = kmalloc(count + 1, GFP_KERNEL); ^~~~~~~ vmalloc /home/linzihao/Code/test/coursework2/work3/my_char_dev.c:20:10: warning: assignment makes pointer from integer without a cast [-Wint-conversion] kbuf = kmalloc(count + 1, GFP_KERNEL); ^ /home/linzihao/Code/test/coursework2/work3/my_char_dev.c:24:9: error: implicit declaration of function ‘kfree’; did you mean ‘vfree’? [-Werror=implicit-function-declaration] kfree(kbuf); ^~~~~ vfree /home/linzihao/Code/test/coursework2/work3/my_char_dev.c: In function ‘dev_exit’: /home/linzihao/Code/test/coursework2/work3/my_char_dev.c:61:20: error: implicit declaration of function ‘class_find’; did you mean ‘devres_find’? [-Werror=implicit-function-declaration] device_destroy(class_find("char_class", NULL), major); ^~~~~~~~~~ devres_find /home/linzihao/Code/test/coursework2/work3/my_char_dev.c:61:20: warning: passing argument 1 ofdevice_destroy’ makes pointer from integer without a cast [-Wint-conversion] In file included from ./include/linux/cdev.h:8:0, from /home/linzihao/Code/test/coursework2/work3/my_char_dev.c:3: ./include/linux/device.h:1216:13: note: expected ‘struct class *’ but argument is of type ‘int’ extern void device_destroy(struct class *cls, dev_t devt); ^~~~~~~~~~~~~~ cc1: some warnings being treated as errors scripts/Makefile.build:340: recipe for target '/home/linzihao/Code/test/coursework2/work3/my_char_dev.o' failed make[2]: *** [/home/linzihao/Code/test/coursework2/work3/my_char_dev.o] Error 1 Makefile:1596: recipe for target '_module_/home/linzihao/Code/test/coursework2/work3' failed make[1]: *** [_module_/home/linzihao/Code/test/coursework2/work3] Error 2 make[1]: 离开目录“/usr/src/linux-headers-4.15.0-213-generic” Makefile:7: recipe for target 'default' failed make: *** [default] Error 2 linzihao@linzihao-virtual-machine:~/Code/test/coursework2/work3$
08-08
#include<ESP32Servo.h> #include <BLEDevice.h> #include <BLEUtils.h> #include <BLEServer.h> #define BLINKER_BLE //使用蓝牙BLE #include <Blinker.h> //#define BLINKER_BLE //使用蓝牙BLE //定义舵机引脚 #define CTW_PIN 13 Servo CTW;//舵机对象 int CTW_angle = 90;//初始角度 const int ANGLE_STEP=5;//角度变换步长 //blinker组件 BlinkerButton ButtonW("btn_w");//定义键位 //BlinkerButton ButtoNA("btn_a"); //BlinkerButton ButtoNS("btn_s"); //BlinkerButton ButtoND("btn_d"); //舵机保护 void setServoAngle(Servo &CTW,int &angle,int newAngle) { newAngle=constrain(newAngle,0,180);//角度限制 angle=newAngle; CTW.write(angle); char buffer[20]; snprintf(buffer,sizeof(buffer),"Angle:%d",angle); Blinker.print(buffer); } void buttonW_callback(const String&state) { setServoAngle(CTW,CTW_angle,CTW_angle+ANGLE_STEP); //delay(150); } void setup() {// put your setup code here, to run once: Serial.begin(115200);//初始化串口 //初始化舵机 CTW.attach(CTW_PIN); //舵机初始位置 setServoAngle(CTW,CTW_angle,90); Blinker.begin();//初始化Blinker //注册按键回调函数 ButtonW.attach(buttonW_callback); } void loop() { // put your main code here, to run repeatedly: Blinker.run(); }这是代码,In file included from d:\Arduino_IDE\locales\hardware\eap32\arduino-esp32-master\libraries\Blinker\src/BlinkerESP32BLE.h:10, from d:\Arduino_IDE\locales\hardware\eap32\arduino-esp32-master\libraries\Blinker\src/Blinker.h:17, from D:\Arduino_IDE\locales\hardware\eap32\arduino-esp32-master\servoa\servoa.ino:6: d:\Arduino_IDE\locales\hardware\eap32\arduino-esp32-master\libraries\Blinker\src/Adapters/BlinkerBLE.h:22:67: error: expected class-name before ',' token 22 | class BlinkerBLE : public BlinkerStream, public BLEServerCallbacks, public BLECharacteristicCallbacks | ^ d:\Arduino_IDE\locales\hardware\eap32\arduino-esp32-master\libraries\Blinker\src/Adapters/BlinkerBLE.h:23:1: error: expected class-name before '{' token 23 | { | ^ d:\Arduino_IDE\locales\hardware\eap32\arduino-esp32-master\libraries\Blinker\src/Adapters/BlinkerBLE.h:49:9: error: 'BLEServer' does not name a type; did you mean 'Server'? 49 | BLEServer *pServer; | ^~~~~~~~~ | Server d:\Arduino_IDE\locales\hardware\eap32\arduino-esp32-master\libraries\Blinker\src/Adapters/BlinkerBLE.h:50:9: error: 'BLEService' does not name a type 50 | BLEService *pService; | ^~~~~~~~~~ d:\Arduino_IDE\locales\hardware\eap32\arduino-esp32-master\libraries\Blinker\src/Adapters/BlinkerBLE.h:51:9: error: 'BLECharacteristic' does not name a type 51 | BLECharacteristic *pCharacteristic; | ^~~~~~~~~~~~~~~~~ d:\Arduino_IDE\locales\hardware\eap32\arduino-esp32-master\libraries\Blinker\src/Adapters/BlinkerBLE.h:52:9: error: 'BLEAdvertising' does not name a type 52 | BLEAdvertising *pAdvertising; | ^~~~~~~~~~~~~~ d:\Arduino_IDE\locales\hardware\eap32\arduino-esp32-master\libraries\Blinker\src/Adapters/BlinkerBLE.h:53:9: error: 'BLEAdvertisementData' does not name a type 53 | BLEAdvertisementData pAdvertisementData; | ^~~~~~~~~~~~~~~~~~~~ d:\Arduino_IDE\locales\hardware\eap32\arduino-esp32-master\libraries\Blinker\src/Adapters/BlinkerBLE.h:64:24: error: 'BLEServer' has not been declared 64 | void onConnect(BLEServer* pServer); | ^~~~~~~~~ d:\Arduino_IDE\locales\hardware\eap32\arduino-esp32-master\libraries\Blinker\src/Adapters/BlinkerBLE.h:65:27: error: 'BLEServer' has not been declared 65 | void onDisconnect(BLEServer* pServer); | ^~~~~~~~~ d:\Arduino_IDE\locales\hardware\eap32\arduino-esp32-master\libraries\Blinker\src/Adapters/BlinkerBLE.h:66:22: error: 'BLECharacteristic' has not been declared 66 | void onWrite(BLECharacteristic *pCharacteristic); | ^~~~~~~~~~~~~~~~~ d:\Arduino_IDE\locales\hardware\eap32\arduino-esp32-master\libraries\Blinker\src/Adapters/BlinkerBLE.h: In member function 'void BlinkerBLE::begin()': d:\Arduino_IDE\locales\hardware\eap32\arduino-esp32-master\libraries\Blinker\src/Adapters/BlinkerBLE.h:73:5: error: 'BLEDevice' has not been declared 73 | BLEDevice::init("Blinker"); | ^~~~~~~~~ d:\Arduino_IDE\locales\hardware\eap32\arduino-esp32-master\libraries\Blinker\src/Adapters/BlinkerBLE.h:74:5: error: 'pServer' was not declared in this scope; did you mean 'Server'? 74 | pServer = BLEDevice::createServer(); | ^~~~~~~ | Server d:\Arduino_IDE\locales\hardware\eap32\arduino-esp32-master\libraries\Blinker\src/Adapters/BlinkerBLE.h:74:15: error: 'BLEDevice' has not been declared 74 | pServer = BLEDevice::createServer(); | ^~~~~~~~~ d:\Arduino_IDE\locales\hardware\eap32\arduino-esp32-master\libraries\Blinker\src/Adapters/BlinkerBLE.h:76:5: error: 'pService' was not declared in this scope 76 | pService = pServer->createService(BLEUUID((uint16_t)0xffe0));//SERVICE_UUID | ^~~~~~~~ d:\Arduino_IDE\locales\hardware\eap32\arduino-esp32-master\libraries\Blinker\src/Adapters/BlinkerBLE.h:76:39: error: 'BLEUUID' was not declared in this scope 76 | pService = pServer->createService(BLEUUID((uint16_t)0xffe0));//SERVICE_UUID | ^~~~~~~ d:\Arduino_IDE\locales\hardware\eap32\arduino-esp32-master\libraries\Blinker\src/Adapters/BlinkerBLE.h:79:5: error: 'pCharacteristic' was not declared in this scope 79 | pCharacteristic = pService->createCharacteristic( | ^~~~~~~~~~~~~~~ d:\Arduino_IDE\locales\hardware\eap32\arduino-esp32-master\libraries\Blinker\src/Adapters/BlinkerBLE.h:81:37: error: 'BLECharacteristic' has not been declared 81 | BLECharacteristic::PROPERTY_READ | | ^~~~~~~~~~~~~~~~~ d:\Arduino_IDE\locales\hardware\eap32\arduino-esp32-master\libraries\Blinker\src/Adapters/BlinkerBLE.h:82:37: error: 'BLECharacteristic' has not been declared 82 | BLECharacteristic::PROPERTY_NOTIFY | | ^~~~~~~~~~~~~~~~~ d:\Arduino_IDE\locales\hardware\eap32\arduino-esp32-master\libraries\Blinker\src/Adapters/BlinkerBLE.h:83:37: error: 'BLECharacteristic' has not been declared 83 | BLECharacteristic::PROPERTY_WRITE_NR | ^~~~~~~~~~~~~~~~~ d:\Arduino_IDE\locales\hardware\eap32\arduino-esp32-master\libraries\Blinker\src/Adapters/BlinkerBLE.h:88:40: error: expected type-specifier before 'BLE2902' 88 | pCharacteristic->addDescriptor(new BLE2902()); | ^~~~~~~ d:\Arduino_IDE\locales\hardware\eap32\arduino-esp32-master\libraries\Blinker\src/Adapters/BlinkerBLE.h:93:5: error: 'pAdvertising' was not declared in this scope 93 | pAdvertising = pServer->getAdvertising(); | ^~~~~~~~~~~~ d:\Arduino_IDE\locales\hardware\eap32\arduino-esp32-master\libraries\Blinker\src/Adapters/BlinkerBLE.h:95:5: error: 'BLEAddress' was not declared in this scope; did you mean 'IPAddress'? 95 | BLEAddress otherAddress = BLEDevice::getAddress(); | ^~~~~~~~~~ | IPAddress d:\Arduino_IDE\locales\hardware\eap32\arduino-esp32-master\libraries\Blinker\src/Adapters/BlinkerBLE.h:97:5: error: 'esp_bd_addr_t' was not declared in this scope; did you mean 'esp_ip_addr_t'? 97 | esp_bd_addr_t ble_m_address; | ^~~~~~~~~~~~~ | esp_ip_addr_t d:\Arduino_IDE\locales\hardware\eap32\arduino-esp32-master\libraries\Blinker\src/Adapters/BlinkerBLE.h:98:12: error: 'ble_m_address' was not declared in this scope 98 | memcpy(ble_m_address, otherAddress.getNative(), ESP_BD_ADDR_LEN); | ^~~~~~~~~~~~~ d:\Arduino_IDE\locales\hardware\eap32\arduino-esp32-master\libraries\Blinker\src/Adapters/BlinkerBLE.h:98:27: error: 'otherAddress' was not declared in this scope 98 | memcpy(ble_m_address, otherAddress.getNative(), ESP_BD_ADDR_LEN); | ^~~~~~~~~~~~ d:\Arduino_IDE\locales\hardware\eap32\arduino-esp32-master\libraries\Blinker\src/Adapters/BlinkerBLE.h:98:53: error: 'ESP_BD_ADDR_LEN' was not declared in this scope 98 | memcpy(ble_m_address, otherAddress.getNative(), ESP_BD_ADDR_LEN); | ^~~~~~~~~~~~~~~ d:\Arduino_IDE\locales\hardware\eap32\arduino-esp32-master\libraries\Blinker\src/Adapters/BlinkerBLE.h:106:5: error: 'pAdvertisementData' was not declared in this scope 106 | pAdvertisementData.setManufacturerData(macStr); | ^~~~~~~~~~~~~~~~~~ d:\Arduino_IDE\locales\hardware\eap32\arduino-esp32-master\libraries\Blinker\src/Adapters/BlinkerBLE.h: In member function 'virtual int BlinkerBLE::print(char*, bool)': d:\Arduino_IDE\locales\hardware\eap32\arduino-esp32-master\libraries\Blinker\src/Adapters/BlinkerBLE.h:247:13: error: 'pCharacteristic' was not declared in this scope 247 | pCharacteristic->setValue(s_send.c_str()); | ^~~~~~~~~~~~~~~ d:\Arduino_IDE\locales\hardware\eap32\arduino-esp32-master\libraries\Blinker\src/Adapters/BlinkerBLE.h: At global scope: d:\Arduino_IDE\locales\hardware\eap32\arduino-esp32-master\libraries\Blinker\src/Adapters/BlinkerBLE.h:260:6: error: variable or field 'onConnect' declared void 260 | void BlinkerBLE::onConnect(BLEServer* pServer) | ^~~~~~~~~~ d:\Arduino_IDE\locales\hardware\eap32\arduino-esp32-master\libraries\Blinker\src/Adapters/BlinkerBLE.h:260:28: error: 'BLEServer' was not declared in this scope; did you mean 'Server'? 260 | void BlinkerBLE::onConnect(BLEServer* pServer) | ^~~~~~~~~ | Server d:\Arduino_IDE\locales\hardware\eap32\arduino-esp32-master\libraries\Blinker\src/Adapters/BlinkerBLE.h:260:39: error: 'pServer' was not declared in this scope; did you mean 'Server'? 260 | void BlinkerBLE::onConnect(BLEServer* pServer) | ^~~~~~~ | Server d:\Arduino_IDE\locales\hardware\eap32\arduino-esp32-master\libraries\Blinker\src/Adapters/BlinkerBLE.h:266:6: error: variable or field 'onDisconnect' declared void 266 | void BlinkerBLE::onDisconnect(BLEServer* pServer) | ^~~~~~~~~~ d:\Arduino_IDE\locales\hardware\eap32\arduino-esp32-master\libraries\Blinker\src/Adapters/BlinkerBLE.h:266:31: error: 'BLEServer' was not declared in this scope; did you mean 'Server'? 266 | void BlinkerBLE::onDisconnect(BLEServer* pServer) | ^~~~~~~~~ | Server d:\Arduino_IDE\locales\hardware\eap32\arduino-esp32-master\libraries\Blinker\src/Adapters/BlinkerBLE.h:266:42: error: 'pServer' was not declared in this scope; did you mean 'Server'? 266 | void BlinkerBLE::onDisconnect(BLEServer* pServer) | ^~~~~~~ | Server d:\Arduino_IDE\locales\hardware\eap32\arduino-esp32-master\libraries\Blinker\src/Adapters/BlinkerBLE.h:273:6: error: variable or field 'onWrite' declared void 273 | void BlinkerBLE::onWrite(BLECharacteristic *pCharacteristic) | ^~~~~~~~~~ d:\Arduino_IDE\locales\hardware\eap32\arduino-esp32-master\libraries\Blinker\src/Adapters/BlinkerBLE.h:273:26: error: 'BLECharacteristic' was not declared in this scope 273 | void BlinkerBLE::onWrite(BLECharacteristic *pCharacteristic) | ^~~~~~~~~~~~~~~~~ d:\Arduino_IDE\locales\hardware\eap32\arduino-esp32-master\libraries\Blinker\src/Adapters/BlinkerBLE.h:273:45: error: 'pCharacteristic' was not declared in this scope 273 | void BlinkerBLE::onWrite(BLECharacteristic *pCharacteristic) | ^~~~~~~~~~~~~~~ Using library ESP32Servo at version 3.0.8 in folder: D:\Arduino_IDE\locales\hardware\eap32\arduino-esp32-master\libraries\ESP32Servo Using library BLE at version 3.2.0 in folder: D:\Arduino_IDE\locales\hardware\eap32\arduino-esp32-master\libraries\BLE Using library Blinker at version 0.3.10230510 in folder: D:\Arduino_IDE\locales\hardware\eap32\arduino-esp32-master\libraries\Blinker Using library Ticker at version 4.4.0 in folder: D:\Arduino_IDE\locales\hardware\eap32\arduino-esp32-master\libraries\Ticker Using library EEPROM at version 3.3.0 in folder: C:\Users\qingc\AppData\Local\Arduino15\packages\esp32\hardware\esp32\3.3.0\libraries\EEPROM Using library Update at version 3.3.0 in folder: C:\Users\qingc\AppData\Local\Arduino15\packages\esp32\hardware\esp32\3.3.0\libraries\Update Using library WiFi at version 3.3.0 in folder: C:\Users\qingc\AppData\Local\Arduino15\packages\esp32\hardware\esp32\3.3.0\libraries\WiFi Using library Networking at version 3.3.0 in folder: C:\Users\qingc\AppData\Local\Arduino15\packages\esp32\hardware\esp32\3.3.0\libraries\Network Using library NetworkClientSecure at version 3.3.0 in folder: C:\Users\qingc\AppData\Local\Arduino15\packages\esp32\hardware\esp32\3.3.0\libraries\NetworkClientSecure exit status 1 Compilation error: exit status 1这是发生的报错,已使用最新的blinker库和ESP32库,请问出现这种报错情况的原因是什么
08-06
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值