I am new to raspberry Pi
Trying to program with C on raspberry and I followed the instruction
http://www.airspayce.com/mikem/bcm2835/index.html
to download the Broadcom library
but Error message popup when i was trying to run the blink sample program
#include <bcm2835.h>
#include <stdio.h>
// Blinks on RPi Plug P1 pin 11 (which is GPIO pin 17)
#define PIN RPI_GPIO_P1_11
int main(int argc, char **argv)
{
// If you call this, it will not actually access the GPIO
// Use for testing
// bcm2835_set_debug(1);
if (!bcm2835_init())
return 1;
// Set the pin to be an output
bcm2835_gpio_fsel(PIN, BCM2835_GPIO_FSEL_OUTP);
// Blink
while (1)
{
// Turn it on
bcm2835_gpio_write(PIN, HIGH);
// wait a bit
bcm2835_delay(500);
// turn it off
bcm2835_gpio_write(PIN, LOW);
// wait a bit
bcm2835_delay(500);
}
bcm2835_close();
return 0;
}
Error Message:
gcc -Wall -o "blink" "blink.c" (in directory: /home/pi/bcm2835-1.50/examples/blink)
/tmp/ccSOd5QT.o: In function `main':
blink.c:(.text+0x14): undefined reference to `bcm2835_init'
blink.c:(.text+0x34): undefined reference to `bcm2835_gpio_fsel'
blink.c:(.text+0x40): undefined reference to `bcm2835_gpio_write'
blink.c:(.text+0x48): undefined reference to `bcm2835_delay'
blink.c:(.text+0x54): undefined reference to `bcm2835_gpio_write'
blink.c:(.text+0x5c): undefined reference to `bcm2835_delay'
Compilation failed.
collect2: error: ld returned 1 exit status
Can anyone explain a little bit what is not properly configured?
Thx.
-
- Posts: 2
- Joined: Fri Aug 12, 2016 3:02 am
Re: Question about error when running example code
Please try to link the object code with proper library.
Re: Question about error when running example code
Which means add "-lbcm2835" to your compiler command line.Mn1 wrote:Please try to link the object code with proper library.
PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson
-
- Posts: 2
- Joined: Fri Aug 12, 2016 3:02 am
Re: Question about error when running example code
thx for the help now it works

