Reputation: 31
How do I compile the code below. They say "compile with -lusb", but I don't know how to do that.
#include <stdio.h>
#include <usb.h>
main(){
struct usb_bus *bus;
struct usb_device *dev;
usb_init();
usb_find_busses();
usb_find_devices();
for (bus = usb_busses; bus; bus = bus->next)
for (dev = bus->devices; dev; dev = dev->next){
printf("Trying device %s/%s\n", bus->dirname, dev->filename);
printf("\tID_VENDOR = 0x%04x\n", dev->descriptor.idVendor);
printf("\tID_PRODUCT = 0x%04x\n", dev->descriptor.idProduct);
}
}
Upvotes: 3
Views: 2517
Reputation: 6059
I was able to successfully compile and run your program.
First, there are three things you should know about -lusb
.
-
means it's an option to the compiler, in my case I use gcc
.l
that prefixes usb
means it is an external library we are including in our compilation of this program.usb
is the library name, and is associated with the #include <usb.h>
(usb is the usb.h excluding its suffix)The command I used:
gcc usb.c -o usb -lusb
I am using gcc 4.7.3
and libusb 1.0.18
Edit: Correctly specify -lusb after the source code file.
Upvotes: 2
Reputation: 84569
You need to add -lusb
to your gcc command:
gcc -Wall -o usb usb.c -lusb
Upvotes: 1