Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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:

int main()
       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
up vote 2 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


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.