0

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.

halfer
  • 19,824
  • 17
  • 99
  • 186
Cleber Marques
  • 426
  • 5
  • 20
  • 1
    All you neead is to locate the libi2c*.* (.a .so, or whatever) and add the lib directory. (-L flag) – SHR Oct 17 '15 at 19:52
  • It's possible the libraries aren't installed, even though the headers are – Russ Schultz Oct 17 '15 at 20:05
  • @SHR, So, all I did to link was: Browsing to "Properties > C/C++ Build > Settings > Cross GCC Linker > Libraries" and added "libi2c-dev" in "Libraries (-l)" and added "/usr/include/linux" in "Library search path (-L)". Still not working! (headache) – Cleber Marques Oct 17 '15 at 22:27

0 Answers0