richtoy
Posts: 14
Joined: Tue Jun 05, 2012 8:35 pm

undefined reference to i2c functions

Wed Oct 10, 2012 7:03 pm

Hi,
I am trying out the Ada I2c interface http://sourceforge.net/projects/raspi-i2c-ada/ and have downloaded and built the library. However, when I try and build the example test program I get the following ld errors: -

Code: Select all

gprbuild test.gpr
gcc-4.6 t.o -o t
/home/pi/raspi-i2c-ada-code/lib-static//libi2c-ada.a(i2c_interface.o): In function `write_quick':
i2c_interface.c:(.text+0x24): undefined reference to `i2c_smbus_write_quick'
/home/pi/raspi-i2c-ada-code/lib-static//libi2c-ada.a(i2c_interface.o): In function `read_byte':
i2c_interface.c:(.text+0x4c): undefined reference to `i2c_smbus_read_byte'
/home/pi/raspi-i2c-ada-code/lib-static//libi2c-ada.a(i2c_interface.o): In function `write_byte':
i2c_interface.c:(.text+0x84): undefined reference to `i2c_smbus_write_byte'
/home/pi/raspi-i2c-ada-code/lib-static//libi2c-ada.a(i2c_interface.o): In function `read_byte_data':
i2c_interface.c:(.text+0xbc): undefined reference to `i2c_smbus_read_byte_data'
/home/pi/raspi-i2c-ada-code/lib-static//libi2c-ada.a(i2c_interface.o): In function `write_byte_data':
i2c_interface.c:(.text+0x104): undefined reference to `i2c_smbus_write_byte_data'
/home/pi/raspi-i2c-ada-code/lib-static//libi2c-ada.a(i2c_interface.o): In function `read_word_data':
i2c_interface.c:(.text+0x13c): undefined reference to `i2c_smbus_read_word_data'
/home/pi/raspi-i2c-ada-code/lib-static//libi2c-ada.a(i2c_interface.o): In function `write_word_data':
i2c_interface.c:(.text+0x184): undefined reference to `i2c_smbus_write_word_data'
/home/pi/raspi-i2c-ada-code/lib-static//libi2c-ada.a(i2c_interface.o): In function `process_call':
i2c_interface.c:(.text+0x1cc): undefined reference to `i2c_smbus_process_call'
/home/pi/raspi-i2c-ada-code/lib-static//libi2c-ada.a(i2c_interface.o): In function `read_block_data':
i2c_interface.c:(.text+0x20c): undefined reference to `i2c_smbus_read_block_data'
/home/pi/raspi-i2c-ada-code/lib-static//libi2c-ada.a(i2c_interface.o): In function `write_block_data':
i2c_interface.c:(.text+0x25c): undefined reference to `i2c_smbus_write_block_data'
/home/pi/raspi-i2c-ada-code/lib-static//libi2c-ada.a(i2c_interface.o): In function `read_i2c_block_data':
i2c_interface.c:(.text+0x2ac): undefined reference to `i2c_smbus_read_i2c_block_data'
/home/pi/raspi-i2c-ada-code/lib-static//libi2c-ada.a(i2c_interface.o): In function `write_i2c_block_data':
i2c_interface.c:(.text+0x2fc): undefined reference to `i2c_smbus_write_i2c_block_data'
/home/pi/raspi-i2c-ada-code/lib-static//libi2c-ada.a(i2c_interface.o): In function `block_process_call':
i2c_interface.c:(.text+0x34c): undefined reference to `i2c_smbus_block_process_call'
collect2: ld returned 1 exit status
gprbuild: link of t.adb failed
I have done some digging around and found that these undefined functions are defined in i2c-dev.h but the question is, where is and how should I link to their implementation/library :?

User avatar
joan
Posts: 14251
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: undefined reference to i2c functions

Wed Oct 10, 2012 7:38 pm

Might be worth checking to see if libi2c-dev is present on your system.

sudo apt-get install libi2c-dev

may be all that you need.

pygmy_giant
Posts: 1562
Joined: Sun Mar 04, 2012 12:49 am

Re: undefined reference to i2c functions

Wed Oct 10, 2012 7:51 pm

drivers schmivers

ada-fruit schmada fruit

libi2c-dev schmlibi2c-dev

I just did this: http://www.njbsmith.net/miscellaneous/I ... 050_test.c

hack it if you can

richtoy
Posts: 14
Joined: Tue Jun 05, 2012 8:35 pm

SOLVED Re: undefined reference to i2c functions

Wed Oct 10, 2012 7:56 pm

Thanks for the reply. I followed the instructions and have installed i2c-tools libi2c-dev and python-smbus. I can see the chip and successfully drive it from the command line with the following: -

Code: Select all

[email protected] ~ $ i2cset -y 0 0x20 0x00 0x00
[email protected] ~ $ i2cset -y 0 0x20 0x01 0x00
[email protected] ~ $ i2cset -y 0 0x20 0x12 0x01
[email protected] ~ $ i2cset -y 0 0x20 0x12 0x02
[email protected] ~ $ i2cset -y 0 0x20 0x12 0x03
[email protected] ~ $ i2cset -y 0 0x20 0x12 0x00
The only issue is linking because I don't appear to be able to find a library containing the missing symbols :?
Last edited by richtoy on Wed Oct 10, 2012 8:19 pm, edited 1 time in total.

techpaul
Posts: 1512
Joined: Sat Jul 14, 2012 6:40 pm
Location: Reading, UK
Contact: Website

Re: undefined reference to i2c functions

Wed Oct 10, 2012 8:06 pm

richtoy wrote:Thanks for the reply. I followed the instructions and have installed i2c-tools libi2c-dev and python-smbus. I can see the chip and successfully drive it from the command line with the following: -

Code: Select all

[email protected] ~ $ i2cset -y 0 0x20 0x00 0x00
[email protected] ~ $ i2cset -y 0 0x20 0x01 0x00
[email protected] ~ $ i2cset -y 0 0x20 0x12 0x01
[email protected] ~ $ i2cset -y 0 0x20 0x12 0x02
[email protected] ~ $ i2cset -y 0 0x20 0x12 0x03
[email protected] ~ $ i2cset -y 0 0x20 0x12 0x00
The only issue is linking because I don't appear to be able to find a library containing the missing symbols :?
Hmm I see you installed python-smbus which is for python, but you are building a gcc (C) porogramme, you have not by chance made reference in your code to python routines instead of C library functions?

Thus confusing the compiler.
Just another techie on the net - For GPIO boards see http:///www.facebook.com/pcservicesreading
or http://www.pcserviceselectronics.co.uk/pi/

sjw
Posts: 2
Joined: Tue Nov 20, 2012 3:27 pm

Re: undefined reference to i2c functions

Tue Nov 20, 2012 3:43 pm

I just came across this post, and helped out @richtoy already. But, for completeness, the problem is that the Linux I2C header <linux/i2c-dev.h> doesn't correspond to any library; instead, all the functions are declared inline. This is fine if you're writing C, but Ada doesn't understand C headers.

My solution was to create a C file which provides a callable interface to each declared function, so that it can be called from Ada using pragma Import.

The project's Makefile is supposed to compile this file and include it in the project library, but something went wrong on @richtoy's machine. AFAICR he retried it and it worked.

Return to “General programming discussion”