Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linking to libusb

Tags:

gcc

linker

I know this is something so simple I'm going to hate myself for having to ask it, but my head is aching from repeated hits on the desktop. I've read dozens of stackoverflow and google results which suggest that the following should work:

$ ls /usr/local/lib/libusb*
/usr/local/lib/libusb-1.0.a   /usr/local/lib/libusb-1.0.so    /usr/local/lib/libusb-1.0.so.0.1.0
/usr/local/lib/libusb-1.0.la  /usr/local/lib/libusb-1.0.so.0
$ gcc -I ~/libusb-1.0.18/libusb -c test.c
$ gcc -L/usr/local/lib -o test test.o -llibusb
/usr/bin/ld: cannot find -llibusb
collect2: error: ld returned 1 exit status
$ gcc -L/usr/local/lib -o test test.o -llibusb-1.0
/usr/bin/ld: cannot find -llibusb-1.0
collect2: error: ld returned 1 exit status

Why is that not correct? One of those should have worked and I've tried many, many more variations.

For completeness I'm running Ubuntu 14.04 (fresh VM installation).

I built libusb from source (~/libusb-1.0.18) with:

./configure --disable-udev
make
sudo make install
like image 216
Tergiver Avatar asked May 24 '14 00:05

Tergiver


1 Answers

The leading lib and trailing .so are automatically filled in by the linker, so you should not specify either on the command line. Your command should be:

gcc -L/usr/local/lib -o test test.o -lusb-1.0
like image 199
nobody Avatar answered Oct 21 '22 08:10

nobody