Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

undefined reference to i2c_smbus_write_byte_data #15

Open
skoehler opened this issue Aug 10, 2017 · 3 comments
Open

undefined reference to i2c_smbus_write_byte_data #15

skoehler opened this issue Aug 10, 2017 · 3 comments

Comments

@skoehler
Copy link

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
Copy link
Owner

hallard commented Aug 15, 2017

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

@skoehler
Copy link
Author

skoehler commented Aug 15, 2017

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
Copy link

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants