So I installed BCM2835 but when I'm trying to compile a .c file with "gcc -c main main.c" it gives the following errors. I have no idea on how to compile linux btw, just follow stuff on the internet.
/tmp/ccSVwHkt.o: In function `main':
main.c:(.text+0x14): undefined reference to `bcm2835_init'
main.c:(.text+0x3c): undefined reference to `bcm2835_gpio_fsel'
main.c:(.text+0x48): undefined reference to `bcm2835_gpio_write'
main.c:(.text+0x50): undefined reference to `bcm2835_delay'
main.c:(.text+0x5c): undefined reference to `bcm2835_gpio_write'
main.c:(.text+0x64): undefined reference to `bcm2835_delay'
collect2: ld returned 1 exit status
This is the content of main.c (copied from Google code)
/*
* main.c
*
* Created on: 23-jun.-2013
* Author: Andreas Backx
*/
#include <bcm2835.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;
}
gcc -c main main.c doesn't make sense given the output you're getting. That said, if it's really what you're doing, you need to change it:
gcc -o main main.c
You'll likely still get the "undefined symbol" errors from the linker, since you're not linking with whatever library defines those symbols. A quick check of the examples at the site you linked shows that you need to link with the bcm2835 library:
gcc -o main main.c -lbcm2835
You may also need to add a -L flag if you installed the library somewhere where gcc doesn't know to look for it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With