I'm using Luna Service Release 2 (4.4.2) with Ubuntu Utopic and the arm-linux-gnueabi-gcc compiler.
I've tried to compile a single program in C to read and write to a device through I2C bus but I'm getting these errors:
make: *** [STRME_v2] Error 1
recipe for target 'STRME_v2' failed
undefined reference to `i2c_smbus_read_byte_data'
undefined reference to `i2c_smbus_write_byte_data'
It looks more like a linker error. The functions i2c_smbus_read_byte_data
and i2c_smbus_write_byte_data
are defined in the libi2c-dev
, so I installed the package libi2c-dev
.
In my code I did:
#include <linux/i2c-dev.h>
#include <linux/i2c.h>
I checked if the i2c-dev.h
and i2c.h
are in the system and I found them in /usr/arm-linux-gnueabi/include/linux
I tried several options to link the project with the library by going to Properties > C/C++ Build > Settings > Cross GCC Linker > Libraries > Libraries (-l)
and adding libi2c-dev
, i2c-dev
and i2c-core
(separately of course) but I got the same error for all: cannot find -li2c-core
/-llibi2c-dev
/-li2c-dev
.
I've no idea how to make it work. I need to make it work for a graduation project.
Response to proposed duplicate
I have written this with a more appropriate, clearer title, and a better explanation.