Question

I know there are a lot of questions up about this issue, but specifically I'm having trouble with an implementation of the libusb library on Ubuntu. Here is my code:

struct usb_bus *busses;
struct usb_bus *bus;
struct usb_device *digiSpark = NULL;
struct usb_device *device;


if(debug) printf("Detecting USB devices...\n");
// Initialize the USB library
usb_init();

// Enumerate the USB device tree
usb_find_busses();
usb_find_devices();

// Iterate through attached busses and devices
busses = usb_get_busses();
for (bus = busses; bus; bus = bus->next)
{
    for (device = bus->devices; device; device = device->next)
    {
        // Check to see if each USB device matches the DigiSpark Vendor and Product IDs
        if((device->descriptor.idVendor == 0x16c0) && (device->descriptor.idProduct == 0x05df))
        {
            if(debug) printf("Detected DigiSpark... \n");
            digiSpark = device;
        }
    }
}

It was taken pretty much verbatim from the libusb example:

http://libusb.sourceforge.net/doc/examples-code.html

But it's generating tons of "dereferencing pointer to incomplete type" errors.

Specifically, I'm getting this dereferencing pointer to incomplete type error on the following lines:

busses = usb_get_busses();

for (bus = busses; bus; bus->next)

for (device = bus->devices; device; device->next)

And twice in the following line:

if((device->descriptor.idVendor == 0x16c0) && (device->descriptor.idProduct == 0x05df))

As I said, this is weird because I'm not (for the most part) making this up, this is taken from the established example off the lib website.

Any suggestions would be great. Thanks!

Was it helpful?

Solution

Turns out I was including the wrong library... though I'm really not sure why. Instead of including I included and referenced the library at compile-time like so:

>> gcc main.c -lusb
>> gcc main.o -o main -lusb

This did it for me and might do it for you! Good luck!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top