Libusb undefined reference to

Reshi picture Reshi · Aug 13, 2011 · Viewed 32.7k times · Source

I'm trying to set up libusb API on my OS. I downloaded libusb api on libusb.org. I followed the standard installation procedure:

cd into directory
./configure
make
make check //without errors
make install

Then I launched Eclipse C/C++ and copied some code from the tutorial found on the internet. But when trying to build it I got following output:

main.cpp:(.text+0x19): undefined reference to `libusb_init'
main.cpp:(.text+0x76): undefined reference to `libusb_set_debug'
main.cpp:(.text+0x8a): undefined reference to `libusb_get_device_list'
main.cpp:(.text+0x136): undefined reference to `libusb_free_device_list'
main.cpp:(.text+0x142): undefined reference to `libusb_exit'
/tmp/ccOWJGwe.o: In function `printdev(libusb_device*)':
main.cpp:(.text+0x162): undefined reference to `libusb_get_device_descriptor'
main.cpp:(.text+0x28a): undefined reference to `libusb_get_config_descriptor'
main.cpp:(.text+0x4d4): undefined reference to `libusb_free_config_descriptor'
collect2: ld returned 1 exit status

I have libusb.so in /lib and also I have usb.h in /usr/local/include and the link for the .so and libusb.a in /usr/local/lib.

Also the #include inside the code is correct.

I know that problem is in linker but I, kind of, cannot make it work :)

I'm using Fedora 15 operating system and gcc 4.6.0 20110603 (Red Hat 4.6.0-10) version compiler.

So what could I do to resolve these undefined references? Thanks very much for help :)

Answer

user3240675 picture user3240675 · Jan 27, 2014

I did face the same problem. But I was able to solve it by adding '-lusb-1.0' to the linker.

e.g : g++ myfile.cpp -lusb-1.0