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

Release notes? #1

Closed
dkossman opened this issue Feb 14, 2013 · 5 comments
Closed

Release notes? #1

dkossman opened this issue Feb 14, 2013 · 5 comments
Labels

Comments

@dkossman
Copy link

This is exactly what I was looking for - I have an Adafruit 2x16 I2C backpack that I want to talk to from C. I tried to build this code on a Pi running Raspbian, but got a ton of errors - is this not compatible with Raspbian? Or is there some prerequisite that I'm missing?

thx


pi@raspberrypi ~/rpi_lcd $ uname -a
Linux raspberrypi 3.6.11+ #371 PREEMPT Thu Feb 7 16:31:35 GMT 2013 armv6l GNU/Linux

pi@raspberrypi ~/rpi_lcd $ make
gcc -Wall -Wextra -Werror -g -o lcd lcd.c
In file included from rpii2c.h:35:0,
from rpii2c.c:26,
from mcp.h:33,
from mcp.c:33,
from lcd.h:36,
from lcd.c:26:
/usr/include/linux/i2c.h:67:8: error: redefinition of ‘struct i2c_msg’
/usr/include/linux/i2c-dev.h:38:8: note: originally defined here
/usr/include/linux/i2c.h:125:7: error: redefinition of ‘union i2c_smbus_data’
/usr/include/linux/i2c-dev.h:90:7: note: originally defined here
In file included from smbus.c:25:0,
from rpii2c.h:37,
from rpii2c.c:26,
from mcp.h:33,
from mcp.c:33,
from lcd.h:36,
from lcd.c:26:
smbus.h:29:14: error: conflicting types for ‘i2c_smbus_access’
/usr/include/linux/i2c-dev.h:161:21: note: previous definition of ‘i2c_smbus_access’ was here
In file included from rpii2c.h:37:0,
from rpii2c.c:26,
from mcp.h:33,
from mcp.c:33,
from lcd.h:36,
from lcd.c:26:
smbus.c: In function ‘i2c_smbus_access’:
smbus.c:48:12: error: assignment from incompatible pointer type [-Werror]
smbus.c: At top level:
smbus.c:57:7: error: redefinition of ‘i2c_smbus_write_quick’
/usr/include/linux/i2c-dev.h:174:21: note: previous definition of ‘i2c_smbus_write_quick’ was here
smbus.c:62:7: error: redefinition of ‘i2c_smbus_read_byte’
/usr/include/linux/i2c-dev.h:179:21: note: previous definition of ‘i2c_smbus_read_byte’ was here
smbus.c:74:7: error: redefinition of ‘i2c_smbus_write_byte’
/usr/include/linux/i2c-dev.h:188:21: note: previous definition of ‘i2c_smbus_write_byte’ was here
smbus.c:80:7: error: redefinition of ‘i2c_smbus_read_byte_data’
/usr/include/linux/i2c-dev.h:194:21: note: previous definition of ‘i2c_smbus_read_byte_data’ was here
smbus.c:93:7: error: redefinition of ‘i2c_smbus_write_byte_data’
/usr/include/linux/i2c-dev.h:204:21: note: previous definition of ‘i2c_smbus_write_byte_data’ was here
smbus.c:101:7: error: redefinition of ‘i2c_smbus_read_word_data’
/usr/include/linux/i2c-dev.h:213:21: note: previous definition of ‘i2c_smbus_read_word_data’ was here
smbus.c:114:7: error: redefinition of ‘i2c_smbus_write_word_data’
/usr/include/linux/i2c-dev.h:223:21: note: previous definition of ‘i2c_smbus_write_word_data’ was here
smbus.c:122:7: error: redefinition of ‘i2c_smbus_process_call’
/usr/include/linux/i2c-dev.h:232:21: note: previous definition of ‘i2c_smbus_process_call’ was here
smbus.c:134:7: error: redefinition of ‘i2c_smbus_read_block_data’
/usr/include/linux/i2c-dev.h:245:21: note: previous definition of ‘i2c_smbus_read_block_data’ was here
smbus.c:149:7: error: redefinition of ‘i2c_smbus_write_block_data’
/usr/include/linux/i2c-dev.h:260:21: note: previous definition of ‘i2c_smbus_write_block_data’ was here
smbus.c:167:7: error: redefinition of ‘i2c_smbus_read_i2c_block_data’
/usr/include/linux/i2c-dev.h:278:21: note: previous definition of ‘i2c_smbus_read_i2c_block_data’ was here
smbus.c:188:7: error: redefinition of ‘i2c_smbus_write_i2c_block_data’
/usr/include/linux/i2c-dev.h:298:21: note: previous definition of ‘i2c_smbus_write_i2c_block_data’ was here
smbus.c:203:7: error: redefinition of ‘i2c_smbus_block_process_call’
/usr/include/linux/i2c-dev.h:314:21: note: previous definition of ‘i2c_smbus_block_process_call’ was here
cc1: all warnings being treated as errors
make: *** [lcd] Error 1

@dkossman
Copy link
Author

it appears that the code will only compile if you remove i2c-dev-tools:
sudo apt-get remove i2c-dev-tools

this is problematic.

@symptog
Copy link
Owner

symptog commented Feb 23, 2013

ok
i'm using rasbian and there is no i2c-dev-tools, i think you meant i2c-tools ;)
so i removed the smbus from the dir and now i'm using the i2c_smbus functions from i2c-tools via #include <i2c-dev.h>
i pushed it and added some things to the readme.

get an update from the repo and
sudo apt-get install i2c-tools libi2c-dev

i think that should fix the problem

@dkossman
Copy link
Author

Sorry for the typo re: i2c-tools, and thanks very much for the update - works like a charm now. Your technique of including code from within .c and .h files is a bit unorthodox, though :-). If I have time (doubtful) I'll take a look at untangling this and having the Makefile generate a more conventional library that can be installed in /usr/local/lib and referenced at link time. In the meantime, it works. Can't argue with success!

@symptog
Copy link
Owner

symptog commented Feb 23, 2013

thanks, its my 1st "lib" ^^

@symptog symptog closed this as completed Feb 23, 2013
@dkossman
Copy link
Author

fyi - to set this up as a library:

  1. change all instances of #include "xxx.c" to #include "xxx.h"
  2. change the Makefile to something like:

SRCS = lcd.c mcp.c rpii2c.c
OBJS = $(patsubst %.c, %.o, $(SRCS))
HDRS = $(patsubst %.c, %.h, $(SRCS))
PROG = lcdtest

CC=gcc
CCFLAGS=-Wall -Wextra -Werror -g

default: $(PROG)

liblcd.a: $(OBJS)
ar rcs $@ $^
ranlib $@

$(PROG): lcdtest.o $(HDRS) liblcd.a Makefile
$(CC) $(CCFLAGS) -o $@ lcdtest.o liblcd.a

clean:
rm -f $(OBJS) $(PROG) liblcd.a

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

No branches or pull requests

2 participants