1
Development and Code Review / libgpio.h: linker command failed
« on: October 25, 2017, 05:36:03 pm »
Hi,
So I'm completely unfamiliar with HardenedBSD aside from what I've picked up over the last week or so. I'm also not a C dev but I work in a small shop and was the one tasked with this.
So I'm just trying to turn some GPIOs on and off. I'm using the libgpio.h library but I'm having linker issues.
Here is my small, simple test script:
I run this in the shell as root, simply, as:
When I try to compile this script in clang (and gcc, went through the nightmare of fumbling through a manual install with no prior knowledge) I get the following linker error:
And here's the more verbose stacktrace:
libgpio.h is where it should be: /usr/include/
And the header's content is as follows:
All of the referenced functions in my test script are where they should be.
So what am I doing wrong here?
So I'm completely unfamiliar with HardenedBSD aside from what I've picked up over the last week or so. I'm also not a C dev but I work in a small shop and was the one tasked with this.
So I'm just trying to turn some GPIOs on and off. I'm using the libgpio.h library but I'm having linker issues.
Here is my small, simple test script:
Code: [Select]
#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;
}
I run this in the shell as root, simply, as:
Quote
# clang gpio_test.c
When I try to compile this script in clang (and gcc, went through the nightmare of fumbling through a manual install with no prior knowledge) I get the following linker error:
Quote
/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'
And here's the more verbose stacktrace:
Quote
FreeBSD clang version 3.8.0 (tags/RELEASE_380/final 262564) (based on LLVM 3.8.0)
Target: x86_64-unknown-freebsd11.0
Thread model: posix
InstalledDir: /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.c
clang -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/include
End 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)
libgpio.h is where it should be: /usr/include/
Quote
# /usr/include # ls -l
total 1928
[...]
-r--r--r-- 1 root wheel 3564 Jul 24 05:19 libgpio.h
[...]
And the header's content is as follows:
Code: [Select]
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_ */
All of the referenced functions in my test script are where they should be.
So what am I doing wrong here?