silverwolfman
Posts: 2
Joined: Fri Aug 12, 2016 3:02 am

Question about error when running example code

Fri Aug 12, 2016 4:02 am

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.

Mn1
Posts: 5
Joined: Fri Aug 12, 2016 7:57 am

Re: Question about error when running example code

Fri Aug 12, 2016 11:52 am

Please try to link the object code with proper library.

User avatar
PeterO
Posts: 6039
Joined: Sun Jul 22, 2012 4:14 pm

Re: Question about error when running example code

Fri Aug 12, 2016 12:30 pm

Mn1 wrote:Please try to link the object code with proper library.
Which means add "-lbcm2835" to your compiler command line.

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

silverwolfman
Posts: 2
Joined: Fri Aug 12, 2016 3:02 am

Re: Question about error when running example code

Mon Aug 15, 2016 1:04 am

thx for the help now it works
:)

Return to “Beginners”