Page 1 of 1

My Pi does not find libusb.h

Posted: Wed Aug 01, 2012 7:26 pm
by robin1508
Hi there,

I wanted to take a look at the libusb library. But I cant even compile a single file including some functions of this library.

This is what I did to install libusb:

Code: Select all

sudo apt-get install libusb-1.0-0

Code: Select all

sudo apt-get install libusb-1.0-0-dev
I even downloaded the latest version from http://www.libusb.org/ and made the make installation.

But if I use

Code: Select all

#include <libusb.h>
the compiler error is:
listdevs.c:24:27: fatal error: libusb/libusb.h: No such file or directory
compilation terminated.
If I use this:

Code: Select all

#include <libusb/libusb.h>
the same error occurs.

or even

Code: Select all

#include </usr/include/libusb-1.0/libusb.h> // this is where the file really is on my Pi!
I get
listdevs.c:(.text+0x28): undefined reference to `libusb_get_device_descriptor'


What did I do wrong?

Re: My Pi does not find libusb.h

Posted: Thu Aug 02, 2012 9:26 pm
by PaulBuxton
I think that you need to specify the include path so that the compiler knows where to find the header file, and then tell the linker to include the libusb library.
so adding something like

Code: Select all

-I/usr/include/libusb-1.0/ -lusb
to your gcc compile options should sort you out.

(note the way that linux/gcc handles library names you don't need to link with -llibusb, just -lusb should do it.

Paul

Re: My Pi does not find libusb.h

Posted: Thu Aug 02, 2012 9:30 pm
by jdbennet
You need to link it. This is normal.

I.e. to use ALSA header files, you need to supply -lasound, for pthreads, -lpthread etc....

Re: My Pi does not find libusb.h

Posted: Fri Aug 03, 2012 1:35 pm
by robin1508
It still does not work.

This is my code:

Code: Select all

#include <stdio.h>
#include </usr/include/libusb-1.0/libusb.h>

int main(int argc, char **argv) {

        libusb_init(NULL);

        printf("Yeah");
        return 0;
}
if I compile this via
gcc -o driver driver.c -I/usr/include/libusb-1.0/ -lusb
the compiler says "/usr/bin/ld: cannot find -lusb"

Re: My Pi does not find libusb.h

Posted: Fri Aug 03, 2012 5:31 pm
by bredman
I think you have to specify the options BEFORE the input files

gcc -lusb driver.c

Re: My Pi does not find libusb.h

Posted: Fri Aug 03, 2012 5:47 pm
by PeterO
It looks like you have not installed the development version of libusb.
sudo apt-get install libusb-1.0-0.dev
(but you say you have......) :?

In your code
#include <libusb.h>
should work if you use this command to compile
gcc -o driver driver.c -I/usr/include/libusb-1.0/ -lusb

The -I tells the compiler to look in "/usr/include/libusb-1.0" for included files.

HTH
PeterO

Re: My Pi does not find libusb.h

Posted: Wed Aug 08, 2012 3:00 pm
by ToSa
I ran into the same issue - and I already had the dev package installed ;)

What I had to do to get it fixed was change the lib from "usb" to "usb-1.0", hence I compiled using the following line:

Code: Select all

gcc -o usbtest usbtest.c -I/usr/include/libusb-1.0/ -lusb-1.0
Cheers,
Tobias

Re: My Pi does not find libusb.h

Posted: Fri Aug 10, 2012 8:45 am
by DAFlippers
Alternatively:

Code: Select all

#include <libusb-1.0/libusb.h>
David

Re: My Pi does not find libusb.h

Posted: Thu Jun 06, 2013 8:31 pm
by lleclerc

Re: My Pi does not find libusb.h

Posted: Tue Jan 21, 2014 2:36 pm
by mko
You should be able to use system libusb see cgminer readmne

./configure --enable-[device] --with-system-libusb

http://ck.kolivas.org/apps/cgminer/

Re: My Pi does not find libusb.h

Posted: Mon Aug 21, 2017 7:45 am
by sanket123
ToSa wrote:
Wed Aug 08, 2012 3:00 pm
I ran into the same issue - and I already had the dev package installed ;)

What I had to do to get it fixed was change the lib from "usb" to "usb-1.0", hence I compiled using the following line:

Code: Select all

gcc -o usbtest usbtest.c -I/usr/include/libusb-1.0/ -lusb-1.0
Cheers,
Tobias
Hi ,

Is your problem solved ?
I am facing same issue.
can u help me?

Re: My Pi does not find libusb.h

Posted: Wed Aug 23, 2017 6:27 pm
by topguy
This is a 3 years old thread, its better to create a new one explaining *your* problem with details and error messages.

Re: My Pi does not find libusb.h

Posted: Sat Dec 07, 2019 1:14 pm
by b.alavi96
None of this solution works.

I solved this by using this in centos 7 :

Code: Select all

yum install libusb*
for ubuntu and others you can use :

Code: Select all

apt-get install libusb*
may be required to execute as root by : sudo

The problem is that libusb development build name was libusbx-dev. :D

Hope to be helpful.