Error: implicit declaration of function ‘i2c_smbus_write_byte’ [-Werror=implicit-function-declaration]

Hi there ,
I was trying to write an application to read and write data to i2c device .previously i had used #include <linux/i2c-dev-user.h> but since i2c-utils was removed from the root filesystem and toolchain for the wp76/77 i am supposed to use #include <linux/i2c-dev.h> but i am stuck with the API’s i am suppose to use as i have used
i2c_smbus_write_byte(i2cdev_fd, enableAllPorts) because of which i have the following errors

1st)
error: implicit declaration of function ‘i2c_smbus_read_byte_data’ [-Werror=implicit-function-declaration]
const int readResult = i2c_smbus_read_byte_data(i2cFd, reg);

error: implicit declaration of function ‘i2c_smbus_write_byte’ [-Werror=implicit-function-declaration]
LE_FATAL_IF(i2c_smbus_write_byte(i2cdev_fd, enableAllPorts) == -1, “failed to write i2c data”);

following are the API’s i have used
–> i2c_smbus_read_byte_data(i2cFd, reg);
–> i2c_smbus_write_byte_data(i2cFd, reg, data);

It would be great if somebody gives me pointers to overcome this issue .

When the change was made to remove i2c tools from yocto, I ended up copying the relevant .h file into the component where I needed it. See: https://github.com/mangOH/GpioExpander/blob/eddfe628188b60efb32a988dfac9c62f50ef6206/gpioExpanderService/gpioExpanderCommon/i2c-utils.h

1 Like

Hi dfrey ,
Thanks for the pointers i was able to solve this issue but now when i run the application it says
Could not open file /dev/i2c-4 or /dev/i2c/4: No such file or directory
but i can see i2c-4 in /dev node , Any comments or pointers on this ?

how you resolved this issue, am too facing the same issue

Hi @kalaivani ,
Please share your error logs and code snippet