I am trying to create a USB device information application using Qt in ubuntu OS. when I try to create a sample application. It gives the following error
main.o: In function `main':
main.cpp:(.text.startup+0x36): undefined reference to `libusb_init'
main.cpp:(.text.startup+0x52): undefined reference to `libusb_get_device_list'
make: Leaving directory `/home/arun/TestProgr-build-desktop-Qt_4_8_1_in_PATH__System__Release'
main.cpp:(.text.startup+0x74): undefined reference to `libusb_get_device_descriptor'
main.cpp:(.text.startup+0x84): undefined reference to `libusb_get_device_address'
main.cpp:(.text.startup+0x8e): undefined reference to `libusb_get_bus_number'
main.cpp:(.text.startup+0xe2): undefined reference to `libusb_free_device_list'
main.cpp:(.text.startup+0xee): undefined reference to `libusb_exit'
collect2: ld returned 1 exit status
make: *** [TestProgr] Error 1
15:32:24: The process "/usr/bin/make" exited with code 2.
Error while building project TestProgr (target: Desktop)
When executing build step 'Make'
Any one please help me to make it work.......
Code
#include <QtCore/QCoreApplication>
#include <libusb-1.0/libusb.h>
#include <stdio.h>
#include <sys/types.h>
static void print_devs(libusb_device **devs)
{
libusb_device *dev;
int i = 0;
while ((dev = devs[i++]) != NULL) {
struct libusb_device_descriptor desc;
int r = libusb_get_device_descriptor(dev, &desc);
if (r < 0) {
fprintf(stderr, "failed to get device descriptor");
return;
}
printf("%04x:%04x (bus %d, device %d)\n",
desc.idVendor, desc.idProduct,
libusb_get_bus_number(dev), libusb_get_device_address(dev));
}
}
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
libusb_device **devs;
int r;
ssize_t cnt;
r = libusb_init(NULL);
if (r < 0)
return r;
cnt = libusb_get_device_list(NULL, &devs);
if (cnt < 0)
return (int) cnt;
print_devs(devs);
libusb_free_device_list(devs, 1);
libusb_exit(NULL);
return a.exec();
}
When I included the library.....
win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../../../usr/local/lib/release/ -lusb-1
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../../../usr/local/lib/debug/ -lusb-1
else:symbian: LIBS += -lusb-1
else:unix: LIBS += -L$$PWD/../../../usr/local/lib/ -lusb-1
NCLUDEPATH += $$PWD/../../../usr/local/include
DEPENDPATH += $$PWD/../../../usr/local/include
It showing cannot find the library
:-1: error: cannot find -lusb-1
But that is exist in that path