undefined reference to i2c_smbus_read_byte_data'

在测试树莓派控制LED教程(http://www.codelast.com/?p=5155)

GPIO测试编译时出现了这个问题

/usr/lib/gcc/arm-linux-gnueabi/4.6/../../../libwiringPi.so:undefined reference to `i2c_smbus_write_byte'
/usr/lib/gcc/arm-linux-gnueabi/4.6/../../../libwiringPi.so:undefined reference to `i2c_smbus_read_byte'
/usr/lib/gcc/arm-linux-gnueabi/4.6/../../../libwiringPi.so:undefined reference to `i2c_smbus_write_byte_data'
/usr/lib/gcc/arm-linux-gnueabi/4.6/../../../libwiringPi.so:undefined reference to `i2c_smbus_write_word_data'
/usr/lib/gcc/arm-linux-gnueabi/4.6/../../../libwiringPi.so:undefined reference to `i2c_smbus_read_word_data'
/usr/lib/gcc/arm-linux-gnueabi/4.6/../../../libwiringPi.so:undefined reference to `i2c_smbus_read_byte_data'
collect2: ld returned 1 exit status


官方论坛上说是少装了库的原因

安装这几个库: i2c-tools,libi2c-dev ,python-smbus

安装参考 sudo apt-get install libi2c-dev

然后重新

make clean

sudo make uninstall


make

sudo make install


重新编译下你的.c文件

gcc led.c -o led -lwiringPi

sudo ./led 4

虽然输入的是4

实际上是GPIO23不停输出高低电平

因为当初写库的时候重新定义了GPIO

(具体可参考https://projects.drogon.net/raspberry-pi/wiringpi/pins/)

晒一张测试照片


undefined reference to i2c_smbus_read_byte_data'_第1张图片




(更多引脚信息可参考http://www.raspberrypi-spy.co.uk/2012/06/simple-guide-to-the-rpi-gpio-header-and-pins/)

实际上是undefined reference to i2c_smbus_read_byte_data'_第2张图片

经测试果然编译通过


(附:WiringPiDownload and Install https://projects.drogon.net/raspberry-pi/wiringpi/download-and-install/)





原文地址

http://www.raspberrypi.org/phpBB3/viewtopic.php?f=31&t=19680

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 
Posts: 9
Joined: Tue Jun 05, 2012 8:35 pm
by  joan » 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.
Posts: 1341
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK
by  pygmy_giant » 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/Ivansense_6050_test.c

hack it if you can
Posts: 1469
Joined: Sun Mar 04, 2012 12:49 am
by  richtoy » 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
pi@raspberrypi ~ $ i2cset -y 0 0x20 0x00 0x00
pi@raspberrypi ~ $ i2cset -y 0 0x20 0x01 0x00
pi@raspberrypi ~ $ i2cset -y 0 0x20 0x12 0x01
pi@raspberrypi ~ $ i2cset -y 0 0x20 0x12 0x02
pi@raspberrypi ~ $ i2cset -y 0 0x20 0x12 0x03
pi@raspberrypi ~ $ 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.
Posts: 9
Joined: Tue Jun 05, 2012 8:35 pm
by  techpaul » 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
pi@raspberrypi ~ $ i2cset -y 0 0x20 0x00 0x00
pi@raspberrypi ~ $ i2cset -y 0 0x20 0x01 0x00
pi@raspberrypi ~ $ i2cset -y 0 0x20 0x12 0x01
pi@raspberrypi ~ $ i2cset -y 0 0x20 0x12 0x02
pi@raspberrypi ~ $ i2cset -y 0 0x20 0x12 0x03
pi@raspberrypi ~ $ 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/
Posts: 764
Joined: Sat Jul 14, 2012 6:40 pm
Location: Reading, UK
by  sjw » 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.

你可能感兴趣的:(undefined reference to i2c_smbus_read_byte_data')