Linking libusb-1.0 to mycfile.c fails
Despite downloading and compiling libusb-1.0 to /usr/local, to know exactky where it is, gcc still can't find it;
gcc -o usb -L/usr/local/lib -llibusb-1.0.so -I/usr/local/include myusbcfile.c gives; usbtest.c:4:15: error: storage size of ‘brd_ftdi’ isn’t known libusb_device brd_ftdi; ^ usbtest.c:5:22: error: storage size of ‘brd_ftdi_handle’ isn’t known libusb_device_handle brd_ftdi_handle; ^ usbtest.c:6:16: error: storage size of ‘context’ isn’t known libusb_context context; ^ This clearly indicates gcc can't find the library, tried different forms of this command, everyone giving this error. |
this error message is not complete,
but to me it looks like you miss an include in your source rather than a linker problem |
looks like an #include "libusb.h" or similar is missing in your c file. it is not about a library but a header file.
|
Nope I've included it with #include <libusb.h> and since /usr/local/include is in the standard include path I use <>. I tested with citations ("") also but same error there.
I only declared three variables in libusb so it couldn't be so much other errors. And the error message is complete in my point of view, since it was all I got. |
/usr/local/include is not the standard include path, therefore you need to use ". You need to show us the c file you wrote, otherwise we can only guess....
|
#include <stdio.h>
#include "libusb-1.0/libusb.h" libusb_device brd_ftdi; libusb_device_handle brd_ftdi_handle; libusb_context context; /* //libusb_init (libusb_context **); libusb_init (&context); libusb_get_device_list(context, &brd_ftdi); libusb_open(brd_ftdi, brd_ftdi_handle); //libusb_exit(struct libusb_context *); libusb_exit(context); */ ----------------------- As you can see I've included libusb.h properly. The function calls are commented since they give even more errors which concludes the same thing. So to track down the error I made it simple to only declare 3 variables. |
actually I still do not know how that libusb was installed, you need to check the location of the file libusb.h. probably it is /usr/local/include/libusb-1.0/libusb.h, but probably not.
Also it was mentioned that is not the full error message, please post the whole output of the command (and also the command itself). |
@BombaD
please read What information to include in a post and how to use code tags and please would you like to ask a moderator to move this thread into the Programming Forum, I think it has more chances for more answers there. |
Except not putting my code in brackets I've followed every guideline in the posting-information.
I compiled libusb-1.0.9 which I downloaded from libusb.org with Code:
./configure --prefix=/usr/local Code:
~$ ls -l /usr/local/include Code:
total 4 Code:
ls -l /usr/local/lib Code:
total 1156 Code:
#include <stdio.h> Code:
#include "libusb-1.0/libusb.h" Code:
gcc -o usb -L/usr/local/lib -llibusb-1.0.so -I/usr/local/include usbtest.c |
and what is the full output of the last command?
please add -Wall. This is the correct syntax I think: gcc -Wall -o usb -I/usr/local/include usbtest.c -L/usr/local/lib -lusb-1.0 |
Oh, sorry... running
Code:
$ gcc -o usb -L/usr/local/lib -llibusb-1.0.so -I/usr/local/include usbtest.c Code:
usbtest.c:4:15: error: storage size of ‘brd_ftdi’ isn’t known Code:
gcc -Wall -o usb -L/usr/local/lib -llibusb-1.0.so -I/usr/local/include usbtest.c Code:
usbtest.c:4:15: error: storage size of ‘brd_ftdi’ isn’t known |
because they have incomplete types
you do not use them as 'value object', just as pointers for communication with libusb Code:
#include <stdio.h> Code:
libusb_context*ctx = 0; the full definition that tells the compiler the size are in a different header, and the libusb devs decided that you do not need to know about these internals, thats ok |
It seems that using pointers yields a slighty different message; with no errors except that gcc still can't find the library despite trying -lusb-1.0.so flag:
Code:
Code:
Code:
#include <stdio.h> |
I told you already: you need to enter: -lusb-1.0 - no lib and no .so required.
|
That did it, thx. I ran this command 3 times and not working according to .bash_history. Must have run it previously without the pointers.
Command: Code:
gcc -o usb -L/usr/local/lib -lusb-1.0 -I/usr/local/include usbtest.c usbtest.c Code:
#include <stdio.h> |
All times are GMT -5. The time now is 02:59 AM. |