[i2c] Simple read byte data compilation problem
khali at linux-fr.org
Tue Oct 21 14:59:56 CEST 2008
On Tue, 21 Oct 2008 11:44:28 +0200, Fabien Marteau wrote:
> I wrote a simple user program to test an i2c bus driver. I found in
> Documentation/i2c/dev-interface their is macro function to read data
> (i2c_smbus_read_byte_data). I used it but I have link error when I compile :
> $ arm-linux-gcc -O i2cread.c -o i2cread
> /tmp/ccfa90st.o: In function `read_byte':
> i2cread.c:(.text+0x3c): undefined reference to `i2c_smbus_read_byte_data'
> collect2: ld returned 1 exit status
> Is someone know what is the problem ?
So let's say you want to access an i2c adapter from a C program. The
first thing to do is "#include <linux/i2c-dev.h>". Please note that
there are two files named "i2c-dev.h" out there, one is distributed
with the Linux kernel and is meant to be included from kernel
driver code, the other one is distributed with i2c-tools and is
meant to be included from user-space programs. You obviously want
the second one here.
Apparently you missed this paragraph.
As a side note, if you only need to test your bus driver, the
i2cdetect, i2cget, i2cset and i2cdump utilities from the i2c-tools
package should be a good start, maybe you don't need to write your own
More information about the i2c