Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I am trying to compile a program that uses libusb library in Ubuntu 12.04. I have installed the libusb-1.0-0-dev. However when I try to compile a program as below:-

#include<usb.h>
#include<stdio.h>
#include<libusb-1.0/libusb.h>
int main()
{
       libusb_init(NULL);            
       return 0;
}

It gives me an error saying

/tmp/ccb75YtE.o: In function 'main': usb.c:(.text+0x11): undefined reference to 'libusb_init' collect2: ld returned 1 exit status

I am using the command cc <file name> -lusb to compile it. What could be the problem?

share|improve this question
    
Nitpicking: Should that be int main() ? (And a return 0; at the end). Not that it matters for this error, but doing it right is a good habit. –  Hennes Apr 5 '13 at 12:49
    
Please edit your answer with the command you are using to compile. If you're using a makefile, post its content too. –  Jesse Apr 5 '13 at 12:54
    
@Jesse Command to compile added. –  PaulDaviesC Apr 5 '13 at 13:08

2 Answers 2

up vote 1 down vote accepted

Try changing the -lusb to -lusb-1.0, like this:
$ cc <file name> -lusb-1.0

share|improve this answer

You have to pass the -lusb command to the linker. You're including the header but you also must link the code to the libusb library (which also must be installed)

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.