LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 01-25-2015, 12:51 PM   #1
BombaD
LQ Newbie
 
Registered: Jan 2015
Posts: 14

Rep: Reputation: Disabled
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.
 
Old 01-26-2015, 06:19 AM   #2
a4z
Senior Member
 
Registered: Feb 2009
Posts: 1,727

Rep: Reputation: 742Reputation: 742Reputation: 742Reputation: 742Reputation: 742Reputation: 742Reputation: 742
this error message is not complete,
but to me it looks like you miss an include in your source rather than a linker problem
 
Old 01-26-2015, 06:47 AM   #3
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 22,167

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

Last edited by pan64; 01-26-2015 at 06:49 AM.
 
Old 01-26-2015, 08:19 AM   #4
BombaD
LQ Newbie
 
Registered: Jan 2015
Posts: 14

Original Poster
Rep: Reputation: Disabled
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.
 
Old 01-26-2015, 08:26 AM   #5
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 22,167

Rep: Reputation: 7393Reputation: 7393Reputation: 7393Reputation: 7393Reputation: 7393Reputation: 7393Reputation: 7393Reputation: 7393Reputation: 7393Reputation: 7393Reputation: 7393
/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....
 
Old 01-26-2015, 09:17 AM   #6
BombaD
LQ Newbie
 
Registered: Jan 2015
Posts: 14

Original Poster
Rep: Reputation: Disabled
#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.

Last edited by BombaD; 01-26-2015 at 09:19 AM.
 
Old 01-26-2015, 09:50 AM   #7
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 22,167

Rep: Reputation: 7393Reputation: 7393Reputation: 7393Reputation: 7393Reputation: 7393Reputation: 7393Reputation: 7393Reputation: 7393Reputation: 7393Reputation: 7393Reputation: 7393
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).
 
Old 01-26-2015, 12:00 PM   #8
a4z
Senior Member
 
Registered: Feb 2009
Posts: 1,727

Rep: Reputation: 742Reputation: 742Reputation: 742Reputation: 742Reputation: 742Reputation: 742Reputation: 742
@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.
 
Old 01-27-2015, 09:48 AM   #9
BombaD
LQ Newbie
 
Registered: Jan 2015
Posts: 14

Original Poster
Rep: Reputation: Disabled
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.
 
Old 01-27-2015, 10:44 AM   #10
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 22,167

Rep: Reputation: 7393Reputation: 7393Reputation: 7393Reputation: 7393Reputation: 7393Reputation: 7393Reputation: 7393Reputation: 7393Reputation: 7393Reputation: 7393Reputation: 7393
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
 
Old 01-28-2015, 09:04 AM   #11
BombaD
LQ Newbie
 
Registered: Jan 2015
Posts: 14

Original Poster
Rep: Reputation: Disabled
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.

Last edited by BombaD; 01-28-2015 at 09:13 AM. Reason: State that this didn't work either
 
Old 01-28-2015, 12:53 PM   #12
a4z
Senior Member
 
Registered: Feb 2009
Posts: 1,727

Rep: Reputation: 742Reputation: 742Reputation: 742Reputation: 742Reputation: 742Reputation: 742Reputation: 742
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
 
Old 01-29-2015, 07:23 PM   #13
BombaD
LQ Newbie
 
Registered: Jan 2015
Posts: 14

Original Poster
Rep: Reputation: Disabled
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.

Last edited by BombaD; 01-29-2015 at 07:25 PM.
 
Old 01-30-2015, 02:01 AM   #14
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 22,167

Rep: Reputation: 7393Reputation: 7393Reputation: 7393Reputation: 7393Reputation: 7393Reputation: 7393Reputation: 7393Reputation: 7393Reputation: 7393Reputation: 7393Reputation: 7393
I told you already: you need to enter: -lusb-1.0 - no lib and no .so required.
 
Old 02-04-2015, 12:18 PM   #15
BombaD
LQ Newbie
 
Registered: Jan 2015
Posts: 14

Original Poster
Rep: Reputation: Disabled
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;
}

Last edited by BombaD; 02-04-2015 at 12:21 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] linking to XInput2.h fails serafean Programming 5 10-05-2010 04:21 PM
[SOLVED] ubuntu 9.10 - #include <libusb/libusb.h> stonehinge03 Linux - Newbie 5 04-20-2010 09:02 AM
usb.h in Eclipse -Fedora 10 /usr/lib/libusb-0.1.so.4.4.4 & dlltool not linking ddeeks Programming 4 05-12-2009 09:19 AM
[SOLVED] Python-2.5 Build Fails; Illegal Instruction Linking Modules weibullguy Linux - Software 1 10-30-2007 01:46 PM
Problem in using both load time linking and runtime linking durgaprasad_j Linux - General 0 08-01-2006 03:49 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 10:50 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration