Library Question

That is plain C.

PS: Save the following as gpiotest.c:
Code:
#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.
 
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?
 
One more dummy question. a.out is the default name for output if none is specified. Is this only clang or most c compilers?
 
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.
 
Back
Top