I'm trying to compile a userspace C sourcefile which uses i2c_smbus_read_*
and i2c_smbus_write_*
functions in a Raspberry Pi 3B+ with kernel 5.10.63-v7+
. It should be possible, according to this Linux kernel document. I already installed libi2c-dev
.
If I use:
#include <linux/i2c.h>
#include <linux/i2c-dev.h>
#include <i2c/smbus.h>
and I run gcc myfile.c -o myfile
, I get:
/usr/bin/ld: /tmp/ccIWkqsK.o: in function `i2c_read':
myfile.c:(.text+0x84): undefined reference to `i2c_smbus_read_byte_data'
/usr/bin/ld: /tmp/ccIWkqsK.o: in function `i2c_write':
myfile.c:(.text+0x160): undefined reference to `i2c_smbus_write_block_data'
collect2: error: ld returned 1 exit status
Which could it be the problem?
Note that these functions are present in my /usr/include/i2c/smbus.h
:
...
extern __s32 i2c_smbus_read_byte_data(int file, __u8 command);
extern __s32 i2c_smbus_write_byte_data(int file, __u8 command, __u8 value);
extern __s32 i2c_smbus_read_word_data(int file, __u8 command);
...