Compiling bcm2835 for c++ with another source code

845 views
Skip to first unread message

Jayaprakash Athimoolam

unread,
Jun 26, 2013, 11:47:49 PM6/26/13
to bcm...@googlegroups.com
Hi -

I am having trouble compiling the shared library with source code in another folder in raspberry pi.

Can any one point me to an example or possibly write a command line to compile say "mytest/test.c" with bcm2835 library.

i am getting something like this
make: *** No rule to make target `bcm2835.h', needed by `test.o'.  Stop.

Thanks
JP

Mike McCauley

unread,
Jun 27, 2013, 1:10:47 AM6/27/13
to bcm...@googlegroups.com
Hello,


On Wednesday, June 26, 2013 08:47:49 PM Jayaprakash Athimoolam wrote:
> Hi -
>
> I am having trouble compiling the shared library with source code in
> another folder in raspberry pi.
>
> Can any one point me to an example or possibly write a command line to
> compile say "mytest/test.c" with bcm2835 library.

See the example command lines at the top of say blink.c:

gcc -o blink -I ../../src ../../src/bcm2835.c blink.c

In your case you might use:

gcc -o test -I /path/to/wherever/bcm2835/bcm2835.c mytest/test.c

Cheers.

>
> i am getting something like this
> make: *** No rule to make target `bcm2835.h', needed by `test.o'. Stop.
>
> Thanks
> JP
--
Mike McCauley mi...@airspayce.com
Airspayce Pty Ltd 9 Bulbul Place Currumbin Waters QLD 4223 Australia
http://www.airspayce.com
Phone +61 7 5598-7474 Fax +61 7 5598-7070

Alexey Vysochin

unread,
Jul 19, 2013, 6:10:26 AM7/19/13
to bcm...@googlegroups.com
Hello Dear!
I am trying to link the application using two librares: Wt(http://www.webtoolkit.eu/) and non-shared library bcm2835(http://www.airspayce.com/mikem/bcm2835/) by two ways:

1. with maikefile (could not link with existing function in libbcm2835.a):

TARGET=$(shell basename 'main')
SOURCES=$(wildcard *.cpp)
OBJECTS=$(SOURCES:%.cpp=%.o)
CFLAGS+=$(shell pkg-config --cflags libwt libwthttp libboost_signals libbcm2835)
LDFLAGS+=$(shell pkg-config --libs libwt libwthttp libboost_signals libbcm2835) 
all: $(TARGET)
$(TARGET):$(OBJECTS)
$(OBJECTS):$(SOURCES)
$(CXX) -o $(TARGET) $(LDFLAGS) $(OBJECTS) $(LOADLIBS) $(LDLIBS)
clean:
$(RM) $(OBJECTS) $(TARGET)
.PHONY: all clean

...in function 'main'
...undefined reference to 'bcm2835_init'
collect2:ld returned 1 exit status

2. with typing the gcc command directly (g++ Wall -o main main.cpp -lwt -lwthttp -lboost_signals -lbcm2835)
/usr/lib/gcc/arm...../libwt.so:undefined reference to 'boost::system::system_category()'
collect2:ld returned 1 exit status

# pkg-config --libs libbcm2835
-L/home/distr/geany/src -lbcm2835

# pkg-config --cflags libbcm2835
-I/home/distr/geany/src


in booth case i get two differents errors.
But siparetly libwt and libbcm2835 librarys are linking with main.o without any error.

HOW TO DO WORK BOOTH LIBRARY TOGETHER?

Mike McCauley

unread,
Jul 19, 2013, 6:28:05 PM7/19/13
to bcm...@googlegroups.com
Hello,

Looks to me like your linking commands are incorrect.
There is no reason I know of that should prevent you linking bcm2835 with any
other non-colliding librray.

Probably your linking commands are not finding the bcm2835 library.

It might help if you showed us the actual ld link command that resulted in
this output:

> ...in function 'main'
> ...undefined reference to 'bcm2835_init'
> collect2:ld returned 1 exit status



Cheers.

Isaiah Fairhurst

unread,
Aug 18, 2013, 1:55:41 PM8/18/13
to bcm...@googlegroups.com
I had a similar problem and found that I was using an older version of the BCM2835 source files.  I downloaded the updated sources and reinstalled the file and voila, the problems went away.  You may want to check which version you have installed on your pi.  The current version is 1.26.

Jayaprakash Athimoolam

unread,
Aug 18, 2013, 2:45:27 PM8/18/13
to bcm...@googlegroups.com
Thanks Isaiah and Mike. I got it to compile and work some time back.
so I installed the bcm library and did the following.

g++ -c demo_raw.cpp                [so this is the file which includes the bcm2835.h and calls the library functions]
g++ -g -Wall -o demo_raw demo_raw.o I2Cdev.o MPU6050.o -l bcm2835

Regards
JP
Reply all
Reply to author
Forward
0 new messages