Error using libusb library
-
I'm working to manage the USB communication between a Qt application and a PIC32 microcontroller device seen as a vendor class device. In the Microchip forum they suggested me to start from one application example written in Qt5 within their MLA library pakage. But now I'm trying to run the example but I get the following errorrs:
:-1: error: skipping incompatible C:\Microchip\mla\v2018_11_26\apps\usb\device\vendor_basic\utilities\libusb_cross_platform_example\src/libusb-1.0.lib when searching for -llibusb-1.0 :-1: error: skipping incompatible C:\Microchip\mla\v2018_11_26\apps\usb\device\vendor_basic\utilities\libusb_cross_platform_example\src/libusb-1.0.dll when searching for -llibusb-1.0 :-1: error: skipping incompatible C:\Microchip\mla\v2018_11_26\apps\usb\device\vendor_basic\utilities\libusb_cross_platform_example\src/libusb-1.0.lib when searching for -llibusb-1.0 :-1: error: skipping incompatible C:\Microchip\mla\v2018_11_26\apps\usb\device\vendor_basic\utilities\libusb_cross_platform_example\src/libusb-1.0.dll when searching for -llibusb-1.0 :-1: error: skipping incompatible C:\Microchip\mla\v2018_11_26\apps\usb\device\vendor_basic\utilities\libusb_cross_platform_example\src\libusb-1.0.lib when searching for -llibusb-1.0 :-1: error: cannot find -llibusb-1.0 :-1: error: collect2.exe: error: ld returned 1 exit status :-1: error: [Makefile.Debug:78: windows/libusb_Demo.exe] Error 1
In the .pro file of the application I have
#------------------------------------------------- # # Project created by QtCreator 2012-06-06T13:21:53 # #------------------------------------------------- QT += core gui QT += widgets TARGET = libusb_Demo TEMPLATE = app SOURCES += main.cpp\ mainwindow.cpp \ usbcomm.cpp HEADERS += mainwindow.h \ usbcomm.h FORMS += mainwindow.ui #------------------------------------------------- # Add LibUSB library #------------------------------------------------- LIBS += -L.\ -llibusb-1.0 #------------------------------------------------- # Make sure to add the required libraries or # frameoworks for the demo work depending on # what OS is being used #------------------------------------------------- macx: LIBS += -framework CoreFoundation win32: LIBS += -lSetupAPI #------------------------------------------------- # Make sure output directory for object file and # executable is in the correct subdirectory #------------------------------------------------- macx { DESTDIR = mac OBJECTS_DIR = mac MOC_DIR = mac UI_DIR = mac RCC_DIR = mac } unix: !macx { DESTDIR = linux OBJECTS_DIR = linux MOC_DIR = linux UI_DIR = linux RCC_DIR = linux } win32 { DESTDIR = windows OBJECTS_DIR = windows MOC_DIR = windows UI_DIR = windows RCC_DIR = windows } OTHER_FILES += win32: LIBS += -L$$PWD/ -llibusb-1.0 INCLUDEPATH += $$PWD/ DEPENDPATH += $$PWD/
and in the README file I read
This is a cross platform project that is similar in functionality as the "plug_and_play_example\src\vc++2008_express" project. However, this version is developed in the Qt 5.x.x development environment (from www.qt.org), and uses the "libusb v1.0.x" APIs. The libusb v1.0.x "driver" provides top level libusb API functions for accessing the USB device, but uses the Microsoft WinUSB driver when the application is used on the Windows platform. Therefore, when this project is built and run on a Windows based machine, install and use the standard WinUSB driver package that comes with this demo, even when using this libusb application project. The libusb-1.0.dll file and respective .lib file provided here are based on the libusb v1.0.19 source. See www.libusb.org for details on the libusb APIs and links to the latest libusb source code and header download. If using this project to build a Linux or Mac OS X executable, make sure that the libusb v1.0.19 driver is available and installed correctly.
What's the problem here?
-
@jsulm Yes the problem was the 32-bit libusb library. I overwite it with the 64-bit version and it works. Thanks.
Now I'd like to know how to modify the project's settings to automatically choose the correct library. My .pro file is the following
#------------------------------------------------- # # Project created by QtCreator 2012-06-06T13:21:53 # #------------------------------------------------- QT += core gui QT += widgets TARGET = libusb_Demo TEMPLATE = app SOURCES += main.cpp\ mainwindow.cpp \ usbcomm.cpp HEADERS += mainwindow.h \ usbcomm.h FORMS += mainwindow.ui #------------------------------------------------- # Add LibUSB library #------------------------------------------------- LIBS += -L.\ -llibusb-1.0 #------------------------------------------------- # Make sure to add the required libraries or # frameoworks for the demo work depending on # what OS is being used #------------------------------------------------- macx: LIBS += -framework CoreFoundation win32: LIBS += -lSetupAPI #------------------------------------------------- # Make sure output directory for object file and # executable is in the correct subdirectory #------------------------------------------------- macx { DESTDIR = mac OBJECTS_DIR = mac MOC_DIR = mac UI_DIR = mac RCC_DIR = mac } unix: !macx { DESTDIR = linux OBJECTS_DIR = linux MOC_DIR = linux UI_DIR = linux RCC_DIR = linux } win32 { DESTDIR = windows OBJECTS_DIR = windows MOC_DIR = windows UI_DIR = windows RCC_DIR = windows } OTHER_FILES += win32: LIBS += -L$$PWD/ -llibusb-1.0 INCLUDEPATH += $$PWD/ DEPENDPATH += $$PWD/
Do you have any suggestion or documentation about the .pro file customization?
-
Hi @Andrew23,
I have the following in one of my projects:
*-msvc* { contains(QMAKE_TARGET.arch, x86_64) { # MSVC 64 bit LIBS += -L$$PWD/ni4882 -lni4882-64 } else { # MSVC 64 bit LIBS += -L$$PWD/ni4882 -lni4882-32 } } else { # MinGW 32 bit LIBS += -L$$PWD/ni4882 -lgpib-32 }
By the way:
LIBS += -L.\ -llibusb-1.0
You are aware that there is already an entry
win32: LIBS += -L$$PWD/ -llibusb-1.0
more below in your.pro
file?$$PWD
refers to the source directory during compilation, btw.I hope that helps,
Regards