How to install libusb in Ubuntu
Asked Answered
N

7

41

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!

Nonmetal answered 31/1, 2011 at 16:33 Comment(5)
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.Nonmetal
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?Hexane
@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.Nonmetal
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?Hexane
@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.Nonmetal
P
86

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

Try

sudo apt-get install libusb-1.0-0-dev
Priority answered 31/1, 2011 at 16:36 Comment(0)
K
29

This should work:

# apt-get install libusb-1.0-0-dev
Karp answered 31/1, 2011 at 16:35 Comment(2)
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".Destruct
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.Unaccountable
P
24

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

Poll answered 22/5, 2014 at 5:34 Comment(1)
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?Phlogistic
C
15

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
Cherie answered 25/3, 2018 at 4:40 Comment(1)
Thanks for this! That -l flag was needed for me, otherwise "undefined reference to libusb_" functions!Classieclassification
B
1

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

Bonnard answered 26/7, 2023 at 11:48 Comment(1)
This doesn't work: bash: ./configure: No such file or directory, there is configure.ac instead.Actinomorphic
U
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.

Unseasoned answered 31/12, 2014 at 2:6 Comment(1)
usb.h is for libusb-0.1 and is outdated.Cherie
D
-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
Drillstock answered 3/2, 2015 at 18:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.