LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Linking libusb-1.0 to mycfile.c fails (https://www.linuxquestions.org/questions/linux-software-2/linking-libusb-1-0-to-mycfile-c-fails-4175532081/)

BombaD 01-25-2015 12:51 PM

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.

a4z 01-26-2015 06:19 AM

this error message is not complete,
but to me it looks like you miss an include in your source rather than a linker problem

pan64 01-26-2015 06:47 AM

looks like an #include "libusb.h" or similar is missing in your c file. it is not about a library but a header file.

BombaD 01-26-2015 08:19 AM

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.

pan64 01-26-2015 08:26 AM

/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....

BombaD 01-26-2015 09:17 AM

#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.

pan64 01-26-2015 09:50 AM

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).

a4z 01-26-2015 12:00 PM

@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.

BombaD 01-27-2015 09:48 AM

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
make
sudo make install

The include file is located is /usr/local/include/libusb-1.0/libusb.h
Code:

~$ ls -l /usr/local/include
Code:

total 4
drwxr-xr-x 2 root root 4096 jan 24 19:58 libusb-1.0

The libfiles are located in /usr/local/lib
Code:

ls -l /usr/local/lib
Code:

total 1156
-rw-r--r-- 1 root root 266594 jan 19 14:57 libftd2xx.a
lrwxrwxrwx 1 root root    34 jan 19 15:56 libftd2xx.so -> /usr/local/lib/libftd2xx.so.1.1.12
-rwxr-xr-x 1 root root 223388 jan 19 14:57 libftd2xx.so.1.1.12
-rw-r--r-- 1 root root 418662 jan 24 19:58 libusb-1.0.a
-rwxr-xr-x 1 root root    953 jan 24 19:58 libusb-1.0.la
lrwxrwxrwx 1 root root    19 jan 24 19:58 libusb-1.0.so -> libusb-1.0.so.0.1.0
lrwxrwxrwx 1 root root    19 jan 24 19:58 libusb-1.0.so.0 -> libusb-1.0.so.0.1.0
-rwxr-xr-x 1 root root 255620 jan 24 19:58 libusb-1.0.so.0.1.0
drwxr-xr-x 2 root root  4096 jan 24 19:58 pkgconfig

My C-file usbtest.c:

Code:

#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);
*/

also tried with;
Code:

#include "libusb-1.0/libusb.h"
compiled with;
Code:

gcc -o usb -L/usr/local/lib -llibusb-1.0.so -I/usr/local/include usbtest.c
There should be no other conflicts since the other folders with libusb is not in standard path and the path is explicitly given to gcc.

pan64 01-27-2015 10:44 AM

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

BombaD 01-28-2015 09:04 AM

Oh, sorry... running
Code:

$ gcc -o usb -L/usr/local/lib -llibusb-1.0.so -I/usr/local/include usbtest.c
gives;
Code:

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;
                ^

and with -Wall;
Code:

gcc -Wall -o usb -L/usr/local/lib -llibusb-1.0.so -I/usr/local/include usbtest.c
gives;
Code:

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;
                ^

Didn't work, and it is the whole error message. When I ran with the function calls, I got several other errors as well saying the functions were not defined so the only conclusion I can make is that it don't somehow finds the declarations. I haven't checked the sources, only the docs but I assume from the docs (where all those functions and variables were listed) they are declared somewhere in my copy of libusb-1.0.9.

a4z 01-28-2015 12:53 PM

because they have incomplete types

you do not use them as 'value object', just as pointers for communication with libusb

Code:

#include <stdio.h>
#include <libusb-1.0/libusb.h>

libusb_device * brd_ftdi;
libusb_device_handle * brd_ftdi_handle;
libusb_context * context;

usage for example

Code:

libusb_context*ctx = 0;
 libusb_init(&ctx); //ponter to a pointer!!!


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

BombaD 01-29-2015 07:23 PM

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:


$ gcc -Wall -o usb -L/usr/local/lib -llibusb-1.0.so -I/usr/local/include usbtest.c

usbtest.c: In function ‘main’:
usbtest.c:6:17: warning: unused variable ‘context’ [-Wunused-variable]
 libusb_context* context;
                ^
usbtest.c:5:24: warning: unused variable ‘brd_ftdi_handle’ [-Wunused-variable]
 libusb_device_handle** brd_ftdi_handle;
                        ^
usbtest.c:4:18: warning: unused variable ‘brd_ftdi’ [-Wunused-variable]
 libusb_device*** brd_ftdi;
                  ^
/usr/bin/ld: cannot find -llibusb-1.0.so
collect2: error: ld returned 1 exit status

Without pointer:
Code:


$ gcc -Wall -o usb -L/usr/local/lib -llibusb-1.0.so -I/usr/local/include usbtest.c

usbtest.c: In function ‘main’:
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;
                ^
usbtest.c:6:16: warning: unused variable ‘context’ [-Wunused-variable]
usbtest.c:5:22: warning: unused variable ‘brd_ftdi_handle’ [-Wunused-variable]
 libusb_device_handle brd_ftdi_handle;
                      ^
usbtest.c:4:15: warning: unused variable ‘brd_ftdi’ [-Wunused-variable]
 libusb_device brd_ftdi;
              ^

And here's the code:

Code:

#include <stdio.h>
#include <libusb-1.0/libusb.h>
int main(void) {
libusb_device* brd_ftdi;
libusb_device_handle** brd_ftdi_handle;
libusb_context* context;
return 0;
}

But nevertheless gcc clearly states it cannot find the library despite using -lusb-1.0.so.

pan64 01-30-2015 02:01 AM

I told you already: you need to enter: -lusb-1.0 - no lib and no .so required.

BombaD 02-04-2015 12:18 PM

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
(-Wall option did also work)

usbtest.c
Code:

#include <stdio.h>
#include <libusb-1.0/libusb.h>
int main() {
libusb_device* brd_ftdi;
libusb_device_handle** brd_ftdi_handle;
libusb_context* context;
return 0;
}



All times are GMT -5. The time now is 02:59 AM.