#include <sys/types.h>#include <err.h>#include <libgpio.h>int main() { gpio_handle_t handle; handle = gpio_open(0); if(handle == GPIO_INVALID_HANDLE) err(1, "gpio_open failed"); gpio_pin_output(handle, 36); gpio_pin_high(handle, 36); gpio_close(handle); return 0;}
# clang gpio_test.c
/tmp/gpio_test-dcfacd.o: In function `main':gpio_test.c:(.text+0x12): undefined reference to `gpio_open'gpio_test.c:(.text+0x42): undefined reference to `gpio_pin_output'gpio_test.c:(.text+0x52): undefined reference to `gpio_pin_high'gpio_test.c:(.text+0x5d): undefined reference to `gpio_close'
FreeBSD clang version 3.8.0 (tags/RELEASE_380/final 262564) (based on LLVM 3.8.0)Target: x86_64-unknown-freebsd11.0Thread model: posixInstalledDir: /usr/bin "/usr/bin/clang" -cc1 -triple x86_64-unknown-freebsd11.0 -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -main-file-name gpio_test.c -mrelocation-model static -mthread-model posix -mdisable-fp-elim -masm-verbose -mconstructor-aliases -munwind-tables -target-cpu x86-64 -v -dwarf-column-info -debugger-tuning=gdb -resource-dir /usr/bin/../lib/clang/3.8.0 -fdebug-compilation-dir /root -ferror-limit 19 -fmessage-length 173 -fobjc-runtime=gnustep -fdiagnostics-show-option -fcolor-diagnostics -o /tmp/gpio_test-400842.o -x c gpio_test.cclang -cc1 version 3.8.0 based upon LLVM 3.8.0 default target x86_64-unknown-freebsd11.0#include "..." search starts here:#include <...> search starts here: /usr/bin/../lib/clang/3.8.0/include /usr/includeEnd of search list. "/usr/bin/ld" --eh-frame-hdr -dynamic-linker /libexec/ld-elf.so.1 --hash-style=both --enable-new-dtags -o a.out /usr/lib/crt1.o /usr/lib/crti.o /usr/lib/crtbegin.o -L/usr/lib /tmp/gpio_test-400842.o -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/lib/crtend.o /usr/lib/crtn.o/tmp/gpio_test-400842.o: In function `main':gpio_test.c:(.text+0x12): undefined reference to `gpio_open'gpio_test.c:(.text+0x42): undefined reference to `gpio_pin_output'gpio_test.c:(.text+0x52): undefined reference to `gpio_pin_high'gpio_test.c:(.text+0x5d): undefined reference to `gpio_close'clang: error: linker command failed with exit code 1 (use -v to see invocation)
# /usr/include # ls -ltotal 1928[...]-r--r--r-- 1 root wheel 3564 Jul 24 05:19 libgpio.h[...]
void gpio_close(gpio_handle_t);/* * Get a list of all the GPIO pins. */int gpio_pin_list(gpio_handle_t, gpio_config_t **);/* * GPIO pin configuration. * * Retrieve the configuration of a specific GPIO pin. The pin number is * passed through the gpio_config_t structure. */int gpio_pin_config(gpio_handle_t, gpio_config_t *);/* * Sets the GPIO pin name. The pin number and pin name to be set are passed * as parameters. */ int gpio_pin_set_name(gpio_handle_t, gpio_pin_t, char *); /* * Sets the GPIO flags on a specific GPIO pin. The pin number and the flags * to be set are passed through the gpio_config_t structure. */ int gpio_pin_set_flags(gpio_handle_t, gpio_config_t *); /* * GPIO pin values. */ int gpio_pin_get(gpio_handle_t, gpio_pin_t); int gpio_pin_set(gpio_handle_t, gpio_pin_t, int); int gpio_pin_toggle(gpio_handle_t, gpio_pin_t); /* * Helper functions to set pin states. */int gpio_pin_low(gpio_handle_t, gpio_pin_t);int gpio_pin_high(gpio_handle_t, gpio_pin_t);/* * Helper functions to configure pins. */int gpio_pin_input(gpio_handle_t, gpio_pin_t);int gpio_pin_output(gpio_handle_t, gpio_pin_t);int gpio_pin_opendrain(gpio_handle_t, gpio_pin_t);int gpio_pin_pushpull(gpio_handle_t, gpio_pin_t);int gpio_pin_tristate(gpio_handle_t, gpio_pin_t);int gpio_pin_pullup(gpio_handle_t, gpio_pin_t);int gpio_pin_pulldown(gpio_handle_t, gpio_pin_t);int gpio_pin_invin(gpio_handle_t, gpio_pin_t);int gpio_pin_invout(gpio_handle_t, gpio_pin_t);int gpio_pin_pulsate(gpio_handle_t, gpio_pin_t);__END_DECLS#endif /* _LIBGPIO_H_ */
# ./a.out
# ./a.out a.out: gpio_open failed: No such file or directory