-1

i am trying to make an aplication where i integrate rfid reader and an LCD, i have acomplished this by two different libraries, wiringPi for LCD and i found a library called rc522 for the rfid. and apart from each other they work great.

The problem is when i try to mix both together, i get compiler errors.

In file included from main.c:20:0:
/usr/local/include/wiringPi.h:216:21: error: conflicting types for ‘bcm2835_delayMicroseconds’
bcm2835.h:912:17: note: previous declaration of ‘bcm2835_delayMicroseconds’ was here

and I found this on the header file, but i have defined it and yet wont work.

 // Historical name compatibility 
#ifndef BCM2835_NO_DELAY_COMPATIBILITY 
#define delay(x) bcm2835_delay(x) 
#define delayMicroseconds(x) bcm2835_delayMicroseconds(x) 
#endif

So i tried comenting this out and was able to compile without errors, but now, when i do lcdClear() from the lcd library on wiringPi i get some weird characters written instead of erasing the lcd screen.

What can i do with this? am i missing something? should i not use both libraries?

This is extra info on the bcm2835:

/// \version 1.10 Changed the names of the delay functions to bcm2835_delay() 
///              and bcm2835_delayMicroseconds() to prevent collisions with wiringPi.
///              Macros to map delay()-> bcm2835_delay() and
///              Macros to map delayMicroseconds()-> bcm2835_delayMicroseconds(), which
///              can be disabled by defining BCM2835_NO_DELAY_COMPATIBILITY
1
  • gcc config.c rfid.c rc522.c main.c -o rc522_reader -lbcm2835 -lwiringPi -lwiringPiDev mysql_config --cflags --libs`` Commented Jul 23, 2015 at 7:31

2 Answers 2

1

As pointed out by this thread:

https://stackoverflow.com/questions/6940384/how-to-deal-with-symbol-collisions-between-statically-linked-libraries

there's an easy way to work around this problem using objcopy.

0

The purpose of that header option is for use with old code, from before the functions were renamed. It would allow you to make the rc522 code compatible without changes with some wiringPi code but only if they are in separate compilation units.

If you do this:

#include <wiringPi.h>
#define BCM2835_NO_DELAY_COMPATIBILITY
#include <rf522.h>

Even if the order is slightly different (the wiringPi include can go anywhere1) and then try and write code in this file, or any file that includes it as a header, all delay() calls are going to be mapped to the function in rf522.h. That is certainly not what you want, because it will screw up the wiringPi code.

You have two choices:

  • Do not define BCM2835_NO_DELAY_COMPATIBILITY, in which case you must never call delay() referring to the method of the rc522 lib. You must use bcm2835_delay() for that instead, and delay() only for the wiringPi method.
  • Do define BCM2835_NO_DELAY_COMPATIBILITY, and separate the logic into two distinct compilation units. In one.c you include wiringPi.h and two.h, in two.c you include rc522.h and one.h. Notice there's a one.c, a one.h, a two.c, and a two.h. This will allow you to use delay() in both .c files.

The second one is probably pointless in your situation unless you have some other reason (e.g., basic modularity) for it, and even then it might as well just start out by using bcm2835_delay(), in which case there is no conflict.

Put another way, unless you are adapting old code (and don't want to just search and replace delay() calls, etc.), you don't need, and should not use BCM2835_NO_DELAY_COMPATIBILITY, but you must then always use the new bcm2835_ function names for the rc522 stuff.

now, when i do lcdClear() from the lcd library on wiringPi i get some weird characters written instead of erasing the lcd screen.

Probably has nothing to do with this. You could confirm in a test program not involving the rfid.


1. For example, your "previous declartion" error indicates you included wiringPi.h after the BCM2835_NO_DELAY_COMPATIBILITY and rc522.h.

2
  • actually that same code gives me a normal lcd clear if done separately, thats why i think it had something to do with it, what i know about this lcd modules is that the command to clear takes/needs some delay so thats why i think it has something to do with it Commented Jul 23, 2015 at 15:24
  • the header files are in /usr/local/inlcudes but where can i find the actual code? to see if they use the delay() or the other functions. Commented Jul 23, 2015 at 19:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.