I am working on customized USB driver for keyboard using libusb. I wrote a simple program and tried to compile that program i received warning and output file is not generated.
This is my program.
#include <stdio.h>
#include <libusb-1.0/libusb.h>
void main(){
usb_init(NULL);
return;
}
The error message is
sample.c: In function ‘main’:
sample.c:7:3: warning: implicit declaration of function ‘usb_init’ [-Wimplicit-function-declaration]
usb_init(NULL);
^
/tmp/ccYbyFAK.o: In function `main':
sample.c:(.text+0xf): undefined reference to `usb_init'
collect2: error: ld returned 1 exit status
I run this commands to set the library lining flag, commands are successfully executed.
pkg-config --list-all
pkg-config --libs libusb
i tried following commands to execute my prog
gcc -o output sample.c -lusb-1.0
gcc -o output sample.c -libusb-1.0
Please help me resolve this issue
You are including the header file for libusb 1.0, but you are using usb_init
, a function that is not part of it's API. Note that libusb 0.1 is really old and has a different API than libusb 1.0. You should refer to the documentation of libusb 1.0 to learn what functions are supported in libusb 1.0: