Stupid Question about C

hey guys I have a library that I want to use for the raspberry pi 2 in c that I downloaded. I installed it but how do I include that project. Explain this to me in an abstract way please?

Abstract you say... Well if it's a compiled library you will have your header files and dll's (or so's). You use the library via headers and link the compiled things into your final executable.

Typically, libraries live in /lib and /usr/lib and headers live in /usr/include. So if the library is installed correctly it will have the library itself (.a file) under /lib or /usr/lib and the header files in /usr/include.

Now you can include the header files you need, by using a preprocessor directive called include that will look like this:

#include <headername.h>

To compile succesfuly you have to "link" the library. Recall that compiling C happens in two steps, compiling and linking. Compiling only looks at header files (.h files) and only cares about -I directives; it output object code (.o files). Linking only cares about -L and -l options and attempts to resolve the symbols in the object code.

So in case the header file you need is in /usr/include you don't need to use the -I directive, you'll only use it to specify a different path to look for header files. But you still need to link the library using -l followed by the library name.

An example command would be:
gcc -o hello hello.c -lncurses
where ncurses is the name of the library. Or
gcc -o hello hello.c -lm
m is the name of the math library, that you would need to link if you include math.h

I have a more specific question. I am using this library.

bcm2835 by Mike McCauley

I am kind of new to c not to programming. I am wondering how to turn on different pins. I am looking at this example. I am wondering if there is a way to select which pin to turn on?

`/ blink.c
//
// Example program for bcm2835 library
// Blinks a pin on an off every 0.5 secs
//
// After installing bcm2835, you can build this
// with something like:
// gcc -o blink blink.c -l bcm2835
// sudo ./blink
//
// Or you can test it before installing with:
// gcc -o blink -I ../../src ../../src/bcm2835.c blink.c
// sudo ./blink
//
// Author: Mike McCauley
// Copyright (C) 2011 Mike McCauley
// $Id: RF22.h,v 1.21 2012/05/30 01:51:25 mikem Exp $

include

include

// 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;

}
`

#define PIN RPI_GPIO_P1_11

Defines a symbolic constant that identify the 17th PIN (pin map here http://elinux.org/RPi_BCM2835_GPIOs). To turn on a pin you first set it as output, then turn its state to HIGH:

bcm2835_gpio_fsel(PIN, BCM2835_GPIO_FSEL_OUTP);
...
bcm2835_gpio_write(PIN, HIGH);

To select another and turn on another pin, do the same using another PIN by changing the PIN parameter in both calls to a different PIN.
Same for turning the pin off.