hallard / ArduiPi_OLED

Common used OLED driver for Raspberry PI
http://hallard.me/adafruit-oled-display-driver-for-pi/
113 stars 59 forks source link

undefined reference to i2c_smbus_write_byte_data #15

Open skoehler opened 7 years ago

skoehler commented 7 years ago

The i2c_smbus_write functions seem to not exist on my system.

gcc -Wall -fPIC -Ofast -mfpu=vfp -mfloat-abi=hard -march=armv6zk -mtune=arm1176jzf-s -c bcm2835.c
bcm2835.c: In function ‘bcm2835_i2c_write’:
bcm2835.c:877:12: warning: implicit declaration of function ‘i2c_smbus_write_byte_data’ [-Wimplicit-function-declaration]
   reason = i2c_smbus_write_byte_data(i2c_fd, buf[0], buf[1]);
            ^~~~~~~~~~~~~~~~~~~~~~~~~
bcm2835.c:880:12: warning: implicit declaration of function ‘i2c_smbus_write_word_data’ [-Wimplicit-function-declaration]
   reason = i2c_smbus_write_word_data(i2c_fd, buf[0], (buf[2]<<8) | buf[1] );
            ^~~~~~~~~~~~~~~~~~~~~~~~~
bcm2835.c:883:12: warning: implicit declaration of function ‘i2c_smbus_write_i2c_block_data’ [-Wimplicit-function-declaration]
   reason = i2c_smbus_write_i2c_block_data(i2c_fd, buf[0], len-1, (const __u8 *) &buf[1]);
            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The compilation work, but when linking the examples we get undefined symbol errors.

g++ -Ofast -mfpu=vfp -mfloat-abi=hard -march=armv6zk -mtune=arm1176jzf-s -Wall  -lArduiPi_OLED oled_demo.cpp -o oled_demo
/usr/local/lib/libArduiPi_OLED.so: undefined reference to `i2c_smbus_write_i2c_block_data'
/usr/local/lib/libArduiPi_OLED.so: undefined reference to `i2c_smbus_write_word_data'
/usr/local/lib/libArduiPi_OLED.so: undefined reference to `i2c_smbus_write_byte_data'
hallard commented 7 years ago

See this Blog comment, should solve your issue ;-)

skoehler commented 7 years ago

I'm using Arch Linux. The problem is not that I'm missing some packages. I have lm_sensors and I have the equivalent of i2c -tools and libi2c-dev installed (/usr/include/linux/i2c-dev.h exists) but the functions like i2c_smbus_write_word_data are simply not part of the header files anymore. On Debian, i2c-dev.h still declares i2c_smbus_write_word_data and friends - but on Arch Linux that is simply not the case.

Looking at the sources of libraries such as MRAA, they just use ioctl's for i2c-IO. The corresponding structs like i2c_smbus_ioctl_data are present in /usr/include/linux/i2c-dev.h.

I believe this library is using functions (that is i2c_smbus_write_word_data and friends) that have been deprecated and are bound to disappear from future releases of the i2c library.

Arch has i2c-tools 3.1.2 while Debian Jessie (and thus Raspbian) has libi2c-dev version 3.1.1.

Workaround: It seems i2c_smbus_write_word_data and friends are inline function that can simply be copied to the source of this library to make things work for now.

TNemes-3141 commented 4 years ago

Hi @skoehler, Is there a workaround for getting the older versions of libi2c-dev and i2c-tools where the commands "i2c_smbus_write_word_data and friends" are included? It seems that these functions are deprecated since a long time now (the newest version of i2c is 4.0) but I need the old commands to compile old libraries that still use them. There isn't a separate package for these versions, so how can I get them?