# Library Question



## Phishfry (Dec 7, 2016)

I am interested in this GPIO Library.
Stupid question. I can't read code yet.
What language is the example using.
https://www.freebsd.org/cgi/man.cgi...h=FreeBSD+11-current&arch=default&format=html


----------



## obsigna (Dec 7, 2016)

That is plain C.

PS: Save the following as gpiotest.c:

```
#include <err.h>
#include <stdint.h>
#include <libgpio.h>

int main(int argc, const char *argv[])
{
    gpio_handle_t handle = gpio_open(0);

    if (handle == GPIO_INVALID_HANDLE)
        err(1, "gpio_open failed");
    gpio_pin_output(handle, 16);
    gpio_pin_high(handle, 16);

    gpio_close(handle);

    return 0;
}
```
Then issue:
`clang -lgpio gpiotest.c -o gpiotest`
`./gpiotest`

Note that GPIO_HANDLE_INVALID in the example is misspelled, apparently this shall be GPIO_INVALID_HANDLE. In addition the header <stdint.h> must be included, in order this snipped can be compiled.


----------



## Phishfry (Dec 7, 2016)

Took me a while to figure out the -l part earlier. The linker. 
The -o output option can go before the .c file right? I did not know the -lgpio part could.
For ncurses learning I stumbed to:
`cc -o HelloWorld helloworld.c -lncurses`

So cc = clang or default system c compiler?


----------



## Phishfry (Dec 7, 2016)

One more dummy question. a.out is the default name for output if none is specified. Is this only clang or most c compilers?


----------



## Phishfry (Dec 7, 2016)

So I see that cc= system compiler

I missed this documentation on first look.
https://www.freebsd.org/doc/en/books/developers-handbook/tools-compiling.html


----------



## obsigna (Dec 7, 2016)

You may place the options on the compiler command line in any convenient order.
You may use cc instead of clang, and this would redirect to the default C compiler, which is clang on FreeBSD ≥ 10.
The linker only links automatically against the C standard library, anything else must be specified by -lxxxx options.
GCC and Clang compile into a.out if you don't specify the name of the output, I cannot tell about other compilers, though.


----------



## fnoyanisi (Dec 8, 2016)

More examples here.


----------

