robin1508
Posts: 4
Joined: Thu Jul 26, 2012 11:16 pm

My Pi does not find libusb.h

Wed Aug 01, 2012 7:26 pm

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?

PaulBuxton
Posts: 57
Joined: Tue Jan 10, 2012 11:38 am

Re: My Pi does not find libusb.h

Thu Aug 02, 2012 9:26 pm

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

jdbennet
Posts: 96
Joined: Sun Jul 22, 2012 2:25 pm

Re: My Pi does not find libusb.h

Thu Aug 02, 2012 9:30 pm

You need to link it. This is normal.

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

robin1508
Posts: 4
Joined: Thu Jul 26, 2012 11:16 pm

Re: My Pi does not find libusb.h

Fri Aug 03, 2012 1:35 pm

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"

bredman
Posts: 1415
Joined: Tue Jan 17, 2012 2:38 pm

Re: My Pi does not find libusb.h

Fri Aug 03, 2012 5:31 pm

I think you have to specify the options BEFORE the input files

gcc -lusb driver.c

User avatar
PeterO
Posts: 5623
Joined: Sun Jul 22, 2012 4:14 pm

Re: My Pi does not find libusb.h

Fri Aug 03, 2012 5:47 pm

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
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

ToSa
Posts: 4
Joined: Fri Jul 06, 2012 4:58 pm

Re: My Pi does not find libusb.h

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

DAFlippers
Posts: 26
Joined: Fri Aug 10, 2012 8:39 am
Location: Berkshire

Re: My Pi does not find libusb.h

Fri Aug 10, 2012 8:45 am

Alternatively:

Code: Select all

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


mko
Posts: 1
Joined: Tue Jan 21, 2014 2:33 pm

Re: My Pi does not find libusb.h

Tue Jan 21, 2014 2:36 pm

You should be able to use system libusb see cgminer readmne

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

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

sanket123
Posts: 9
Joined: Wed Aug 09, 2017 1:06 pm

Re: My Pi does not find libusb.h

Mon Aug 21, 2017 7:45 am

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?

User avatar
topguy
Posts: 6288
Joined: Tue Oct 09, 2012 11:46 am
Location: Trondheim, Norway

Re: My Pi does not find libusb.h

Wed Aug 23, 2017 6:27 pm

This is a 3 years old thread, its better to create a new one explaining *your* problem with details and error messages.

b.alavi96
Posts: 1
Joined: Sat Dec 07, 2019 1:09 pm

Re: My Pi does not find libusb.h

Sat Dec 07, 2019 1:14 pm

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.

Return to “C/C++”