In raspberry pi , we got two famous libraries (a) bcm2835 and (b)wiringpi. So,I want to use some header files from library bcm2835 and some from wiringpi in a same code. Is it possible to do so. If so, what should be the format for compiling my code?


I think that the format should be C/C++. If I'm right, the bcm2835 library can be used in C and C++ code. About wiringpi I'm not sure. And about your question, it's possible to mix the two libraries for different purpose. You can try, you can't broke anything.

But, I have a question! If I'm right, both libraries are for controlling the GPIO pins. Why do you want to mix these libraries when both give you almost the same or the same features? I think, that it would be better if you choose the library that fits to your needs, is light and you can implement your ideas easily. So you'll have to see which of these two fits better to your needs and what is your effort to implement your ideas if you use one of those 2 libraries.

I think it's not needed to use both because you'll just increase the size of your executable and also, is useless to use same features from 2 different libraries.

| improve this answer | |
  • Actually I am newbie in raspberry pi. I learn gpio and timer using bcm2835 library. then I tried UART, but in UART i got some issues so I switch to wiring pi(I post my UART issue on this site as well here is the link :- raspberrypi.stackexchange.com/questions/26427/…). That's why I decide to use both. – Tabish Saifullah Jan 3 '15 at 9:00
  • Understood! You can use both libraries. What I wanted to say in my comment is that is not, maybe recommended, to use 2 libraries that do the same thing, but for learning, is OK. As an answer to your question, is possible to use both. But don't mix them because you'll maybe have errors. For example, don't declare a pin with bcm2835 library and then use that pin in wiringpi functions or vice versa. If you declare a pin with bcm2835 use it only in functions from bcm2835 functions, and the same rule for wiringpi – 23ars Jan 3 '15 at 9:11
  • ok, I got it. But how to compile my code with both libraries? – Tabish Saifullah Jan 3 '15 at 9:20
  • gcc yourfile.c -lbcm2835 -l wiringPi -o executable_name If it's not finding the wiringPi, try -lwiringPi instead of -l wiringPi. I found on a website the wiringPi parameter but I'm not sure if it's correct with space between -l and the name of the library. – 23ars Jan 3 '15 at 9:23
  • 2
    @TabishSaifullah I suggest your time would be better spent trying to understand why your serial code doesn't work. Hopping between libraries is a short term approach. – joan Jan 3 '15 at 9:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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