Using libusb-1.0 with Qt (MinGW) in Windows 8
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)
Code:
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
Code:
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
Code:
#include <libusb.h>
(then autosubstitution showed functions from libusb)
4. added call of libusb_init(NULL);
Code:
int main(int argc, char *argv[])
{
libusb_init(NULL);
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?
Re: Using libusb-1.0 with Qt (MinGW) in Windows 8
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
Code:
LIBS += -L C:\Qt\libusb-1.0.20\MinGW32\static -l usb-1.0
Cheers,
_
Re: Using libusb-1.0 with Qt (MinGW) in Windows 8
... moreover, libusb is a C library. I include in my C++ code (Debian here! Patch to your Windows!):
Code:
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.