Results 1 to 3 of 3

Thread: Using libusb-1.0 with Qt (MinGW) in Windows 8

  1. #1

    Default 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)
    Qt Code:
    1. libusb-1.0.20
    2. examples
    3. include
    4. libusb-1.0
    5. libusb.h
    6. MinGW32
    7. dll
    8. libusb-1.0.dll
    9. libusb-1.0.dll.a
    10. static
    11. libusb-1.0.a
    12. MinGW64
    13. MS32
    14. MS64
    15. libusb-1.0.def
    16. README.txt
    To copy to clipboard, switch view to plain text mode 

    1. I have created an empty project
    2. added to .pro
    Qt Code:
    1. INCLUDEPATH += C:\Qt\libusb-1.0.20\include\libusb-1.0\
    2. LIBS += C:\Qt\libusb-1.0.20\MinGW32\static\libusb-1.0.a
    To copy to clipboard, switch view to plain text mode 

    3. added to main.cpp
    Qt Code:
    1. #include <libusb.h>
    To copy to clipboard, switch view to plain text mode 
    (then autosubstitution showed functions from libusb)

    4. added call of libusb_init(NULL);
    Qt Code:
    1. int main(int argc, char *argv[])
    2. {
    3. libusb_init(NULL);
    4.  
    5. QApplication a(argc, argv);
    6. MainWindow w;
    7. w.show();
    8.  
    9. return a.exec();
    10. }
    To copy to clipboard, switch view to plain text mode 


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

    Can someone tell me where I'm going wrong?

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default 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

    Qt Code:
    1. LIBS += -L C:\Qt\libusb-1.0.20\MinGW32\static -l usb-1.0
    To copy to clipboard, switch view to plain text mode 

    Cheers,
    _

  3. #3
    Join Date
    Apr 2013
    Location
    Prague
    Posts
    258
    Thanks
    3
    Thanked 65 Times in 59 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default 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!):
    Qt Code:
    1. extern "C"
    2. {
    3. #include <libusb-1.0/libusb.h>
    4. }
    To copy to clipboard, switch view to plain text mode 
    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.

Similar Threads

  1. g++ on Windows (mingw-w64)
    By mdavidjohnson in forum Newbie
    Replies: 1
    Last Post: 14th April 2016, 17:48
  2. Linux, libusb and Qt
    By jacaz4 in forum Newbie
    Replies: 8
    Last Post: 30th July 2015, 09:27
  3. Using libusb with QT Creator in Windows
    By dching in forum Newbie
    Replies: 1
    Last Post: 5th August 2014, 22:37
  4. Windows 7 + Qt + mingw 64-bit
    By serge_malo in forum Newbie
    Replies: 0
    Last Post: 30th September 2010, 13:59
  5. QT 4.2.2 Windows Mingw
    By KaptainKarl in forum Installation and Deployment
    Replies: 3
    Last Post: 4th May 2007, 15:57

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.