45

I want to install libusb in ubuntu 14.04 LTS. I have downloaded libusb-1.0.9.tar.bz2 file from official site "http://libusb.org" but now I am unable to install it. I want to use libusb for Reliance usb for net connection.

As I am new to linux so please mention every command that I need to run in terminal.

Thanks in advance.

Priyansh
  • 1,051
  • :) it's difficult to choose here, but you better do it. So we keep the community alive. Check https://meta.askubuntu.com/questions/14593/is-it-ok-to-not-accept-an-answer-out-of-many-equally-good-ones then please accept one. – user.dz Nov 28 '15 at 15:51

2 Answers2

66

This is how you install libusb:

sudo apt-get install libusb-1.0-0-dev

Note that if you are using libusb in a C/C++ program you should include it the following way:

#include <libusb-1.0/libusb.h>

and not like this:

#include <libusb.h>

This is a common mistake that I was making. Finally you compile like this:

g++ source.cpp `pkg-config --libs --cflags libusb-1.0`
daltonfury42
  • 5,499
  • 1
    Not sure that you need to specify the version. sudo apt-get install libusb-dev worked fine for me. – MisterSeajay Dec 06 '16 at 21:19
  • @CharlieJoynt In that case, how did you include libusb in your code and how did you compile it? – daltonfury42 Dec 07 '16 at 06:56
  • 1
    I came across this when trying to ./configure the libmtp library from Sourceforge. It was failing with an error saying the libusb library was missing. I resolved it with the command in my comment above. 'fraid it has been a long while since I wrote any C/C++ code myself. Since the OP only mentioned installing the package, I thought it might be useful to share my experience. – MisterSeajay Dec 07 '16 at 09:09
  • 1
    I had a face-in-palm moment when I realized I had to omit "lib" from "libusb-1.0" in order to get ld to find the library. Just like -lz links libz.so, "-lusb-1.0" is the correct string. – stephen Apr 23 '18 at 18:53
  • @CharlieJoynt You should specify the version, or at least be aware if your program needs a particular version, because on some platforms libusb-dev is not the same as libusb-1.0-0-dev (e.g. Raspberry Pi). – Josh Feb 12 '19 at 00:03
  • You will sometimes also require libudev-dev – workflow Dec 09 '19 at 14:30
6

Since you are new to linux I suggest running the below command from terminal to install libusb directly from the repository:

>sudo apt-get install libusb-1.0-0-dev

If you wish to continue with the archive you have downloaded, refer to the instructions in the below link:

http://www.linuxfromscratch.org/blfs/view/svn/general/libusb.html

Ron
  • 20,638