PDA

View Full Version : Using libusb-1.0 with Qt (MinGW) in Windows 8



flammmable
22nd June 2016, 09:59
Hello!
I try to connect device (STM32-Nucleo) with PC via USB.
I have downloaded Qt-5.7.0 with MinGW-5.3.0 and libusb-1.0.20.

(folders of libusb-1.0.20)


libusb-1.0.20
examples
include
libusb-1.0
libusb.h
MinGW32
dll
libusb-1.0.dll
libusb-1.0.dll.a
static
libusb-1.0.a
MinGW64
MS32
MS64
libusb-1.0.def
README.txt


1. I have created an empty project
2. added to .pro

INCLUDEPATH += C:\Qt\libusb-1.0.20\include\libusb-1.0\
LIBS += C:\Qt\libusb-1.0.20\MinGW32\static\libusb-1.0.a

3. added to main.cpp

#include <libusb.h>
(then autosubstitution showed functions from libusb)

4. added call of libusb_init(NULL);

int main(int argc, char *argv[])
{
libusb_init(NULL);

QApplication a(argc, argv);
MainWindow w;
w.show();

return a.exec();
}


But. There is an error
In function `Z5qMainiPPc':
undefined reference to `libusb_init@4'

Can someone tell me where I'm going wrong?

anda_skoa
22nd June 2016, 11:19
The LIBS variable is usually an -L directive with the directory the library is in and an -l directive with the library name (without any extension of lib prefix)

So maybe try



LIBS += -L C:\Qt\libusb-1.0.20\MinGW32\static -l usb-1.0


Cheers,
_

Radek
24th June 2016, 08:10
... moreover, libusb is a C library. I include in my C++ code (Debian here! Patch to your Windows!):


extern "C"
{
#include <libusb-1.0/libusb.h>
}

most likely, replace "libusb-1.0" with "libusb-1.0.20" and remove the INCLUDEPATH addition. Moreover, in Debian, accessing a USB device needs root privileges so that bye bye debugger.