LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
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 02-04-2015, 01:03 PM   #1
BombaD
LQ Newbie
 
Registered: Jan 2015
Posts: 14

Rep: Reputation: Disabled
libusb-1.0 libusb_get_device_list() failure


Also tested with -Wall and -std=c99 and c11 (not working of course)
Code:
$ gcc -o usb -L/usr/local/lib -lusb-1.0 -I/usr/local/include usbtest.c
Output:
Code:
usbtest.c: In function ‘main’:
usbtest.c:14:1: error: label ‘brd_ftdi’ used but not defined
 libusb_get_device_list(context, &&brd_ftdi);
 ^
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;

//libusb_device *** list = &&brd_ftdi;


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

return 0;
}
Not defined? I know, but libusb_get_device_list() is supposed to do it (put the list in there), so WTF? I also tested declaring a pointer to pointer to brd_ftdi and passing that on instead but same result.
 
Old 02-04-2015, 01:51 PM   #2
smallpond
Senior Member
 
Registered: Feb 2011
Location: Massachusetts, USA
Distribution: Fedora
Posts: 3,994

Rep: Reputation: 1218Reputation: 1218Reputation: 1218Reputation: 1218Reputation: 1218Reputation: 1218Reputation: 1218Reputation: 1218Reputation: 1218
You are trying to create a pointer to a pointer out of thin air. Where does it put that intermediate pointer?
Try:
Code:
libusb_device **brd_ftdi;
n = libusb_get_device_list(context, &brd_ftdi);
 
Old 02-16-2015, 08:30 AM   #3
BombaD
LQ Newbie
 
Registered: Jan 2015
Posts: 14

Original Poster
Rep: Reputation: Disabled
Somewhere in the memory I guess. Isn't your method the same thing? you're using a double pointer instead of a single like I did and hence pass only one & to the method.
 
Old 02-16-2015, 09:07 AM   #4
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 20,227

Rep: Reputation: 6834Reputation: 6834Reputation: 6834Reputation: 6834Reputation: 6834Reputation: 6834Reputation: 6834Reputation: 6834Reputation: 6834Reputation: 6834Reputation: 6834
no you have misunderstood:
& means address of, so &brd_ftdi means the location where the variable brd_ftdi is stored.
* means pointer, ** means a pointer to a pointer (* means a variable which contains the address of another thing, ** means a variable which contains the address of another variable, which contains the address of another one...)
But && as (address of the address of something) has no any meaning, this syntax does not exist - because the address of variable is not yet stored anywhere. && is the logical and operator.
The line cannot be properly parsed and an error message was dropped....
 
Old 03-27-2015, 08:06 AM   #5
BombaD
LQ Newbie
 
Registered: Jan 2015
Posts: 14

Original Poster
Rep: Reputation: Disabled
Using * gives
Code:
schtern@frmscrpyrd:~$ gcc -o usb -Wall -L/usr/local/lib -lusb-1.0 -I/usr/local/include usbtest.c
usbtest.c: In function main:
usbtest.c:12:14: error: dereferencing pointer to incomplete type
 libusb_init (*context);
              ^
usbtest.c:14:33: error: dereferencing pointer to incomplete type
 libusb_get_device_list(context,**brd_ftdi);
                                 ^
usbtest.c:16:25: error: dereferencing pointer to incomplete type
 libusb_free_device_list(*brd_ftdi,0);
                         ^
usbtest.c:5:24: warning: unused variable brd_ftdi_handle [-Wunused-variable]
 libusb_device_handle** brd_ftdi_handle;
                        ^
Using & gives
Code:
$ gcc -o usb -Wall -L/usr/local/lib -lusb-1.0 -I/usr/local/include usbtest.c


usbtest.c: In function main:
usbtest.c:14:1: error: label brd_ftdi used but not defined
 libusb_get_device_list(context,&&brd_ftdi);
 ^
usbtest.c:5:24: warning: unused variable brd_ftdi_handle [-Wunused-variable]
 libusb_device_handle** brd_ftdi_handle;
                        ^
 
  


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
Libusb 1.0.19 Compilation burhaneyuboglu Linux - Software 17 11-18-2014 08:32 AM
LibUSB on PIC18F4550 jeanCarloMachado Linux - Newbie 2 10-27-2011 01:56 AM
want to use libusb in C, but confused ... cjh21017 Linux - Software 3 06-16-2011 05:32 PM
[SOLVED] ubuntu 9.10 - #include <libusb/libusb.h> stonehinge03 Linux - Newbie 5 04-20-2010 09:02 AM
help me --- interrupt_read() in libusb shiva_teknic Programming 0 09-27-2005 08:17 AM

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

All times are GMT -5. The time now is 10:05 AM.

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