40

I have a C program that have #include part in the header.

I have download libusb-1.0.0 to my computer. If I simply copy libusb-1.0.0 folder to the folder where my C program is, it will not work. Therefore, I think I have to somehow install libuse-1.-.- to the folder where my C program is. However, I do not how to install it.

Could anybody please help me. Thanks!

John
  • 3,888
  • 11
  • 46
  • 84
  • 1
    I need to install it to the folder of my C program. Otherwise, it will not work. sudo apt-get install libusb-1.0-0-dev or # apt-get install libusb-dev can not help. – John Jan 31 '11 at 17:24
  • Don't understand this. You say you copied libusb to the folder of your C program and it didn't work. And now you say you need to copy it to the folder of your C program or otherwise it will not work. Can you give a more detailed description of your problem? – kayahr Feb 01 '11 at 17:08
  • @kayahr: thanks for reply. I did not say i need to copy it to the C program folder. I said I need to install it to the C program folder. Copy and install are different. Just like in Windows, you install MS Office to Programs folder, you do not simply copy MS Office file to Programs folder. That is what I mean. – John Feb 02 '11 at 20:54
  • Can you describe what files are expected after "installation"? Do you need the libusb.so and usb.h file in the root of your C program folder? Or must it be installed into "lib" and "include" sub directories? Or any other directory structure? – kayahr Feb 02 '11 at 23:10
  • @kayahr: thanks for trying to help me. I actually solved my problem today. I just extract the libusb.zip file and change the directory of #include in my C program to the extracted folder. – John Feb 03 '11 at 14:49

7 Answers7

85

Usually to use the library you need to install the dev version.

Try

sudo apt-get install libusb-1.0-0-dev
Gazler
  • 83,029
  • 18
  • 279
  • 245
29

This should work:

# apt-get install libusb-1.0-0-dev
Ton van den Heuvel
  • 10,157
  • 6
  • 43
  • 82
  • 1
    I did that, and it took me through the installation dialog, but it's still not working for me. The man page isn't showing up and when I try to include libusb.h, I get "no such file or directory". – rurouniwallace Sep 06 '12 at 19:08
  • This installs development support for the **old** version of libusb, the poster wants to install support for libusb-1.0 which has a different API. – Chris Stratton Jan 03 '14 at 18:24
23

First,

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

updatedb && locate libusb.h.

Second, replace <libusb.h> with <libusb-1.0/libusb.h>.

update:

don't need to change any file.just add this to your Makefile.

`pkg-config libusb-1.0 --libs --cflags`

its result is that -I/usr/include/libusb-1.0 -lusb-1.0

Brighter side
  • 392
  • 2
  • 14
kangear
  • 2,493
  • 2
  • 31
  • 44
  • where to add this in the Makefile? no matter where I add this, I get some Makefile errors like "missing separator" - and also do I need to use these backticks? – MilMike Dec 19 '20 at 19:52
14

Here is what worked for me.

Install the userspace USB programming library development files

sudo apt-get install libusb-1.0-0-dev
sudo updatedb && locate libusb.h

The path should appear as (or similar)

/usr/include/libusb-1.0/libusb.h

Include the header to your C code

#include <libusb-1.0/libusb.h>

Compile your C file

gcc -o example example.c -lusb-1.0
mrbean
  • 547
  • 5
  • 14
  • 2
    Thanks for this! That -l flag was needed for me, otherwise "undefined reference to libusb_" functions! – sent1nel Feb 07 '19 at 18:15
0

"I need to install it to the folder of my C program." Why?

Include usb.h:

#include <usb.h>

and remember to add -lusb to gcc:

gcc -o example example.c -lusb

This work fine for me.

Dennis NP
  • 9
  • 1
0

Recommended method for installing the latest libusb library on any linux system is by building it from source code.

Below are the steps to build libusb source code and install it correctly on your ubuntu system:

git clone https://github.com/libusb/libusb.git
git checkout tags/v1.0.22 -b V1.0.22
./configure --enable-udev --disable-static
make
sudo make install

Communication between a user space C program and a USB device, users can refer to the API documentation https://libusb.sourceforge.io/api-1.0/index.html

shashank arora
  • 1,176
  • 11
  • 14
-2

you can creat symlink to your libusb after locate it in your system :

sudo ln -s /lib/x86_64-linux-gnu/libusb-1.0.so.0 /usr/lib/libusbx-1.0.so.0.1.0 

sudo ln -s /lib/x86_64-linux-gnu/libusb-1.0.so.0 /usr/lib/libusbx-1.0.so
VirtualTroll
  • 3,077
  • 1
  • 30
  • 47