Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct


    Qt World Summit: Early-Bird Tickets

    Linking libusb-1.0.a into a simple test project

    General and Desktop
    2
    2
    5103
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • T
      Trenelly last edited by

      I am trying to link libusb-1.0.a into my project to test some usb functions. However, I keep getting reference errors on the library functions. My pro file was generated by the qt gui. I also used the gui to add the library. The file is below:.

      TEMPLATE = app
      CONFIG += console
      CONFIG -= app_bundle
      CONFIG -= qt

      SOURCES += main.cpp

      win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../../../../../libusb/MinGW32/static/ -llibusb-1

      INCLUDEPATH += $$PWD/../../../../../libusb/MinGW32/static
      DEPENDPATH += $$PWD/../../../../../libusb/MinGW32/static

      HEADERS += libusb.h


      My code is:

      #include <iostream>
      #include "C:\libusb\include\libusb-1.0\libusb.h"

      using namespace std;

      libusb_context * lc;
      libusb_hotplug_callback_handle h;

      int main()
      {
      libusb_hotplug_deregister_callback(lc, h);

      return 0;
      

      }


      The error messages are:

      17:39:28: Running steps for project libusbtest...
      17:39:28: Configuration unchanged, skipping qmake step.
      17:39:28: Starting: "C:\Qt\Tools\mingw482_32\bin\mingw32-make.exe"
      C:/Qt/Tools/mingw482_32/bin/mingw32-make -f Makefile.Debug
      mingw32-make[1]: Entering directory 'C:/Qt/Projects/OPVCon/libusbtest/build-libusbtest-Desktop_Qt_5_3_MinGW_32bit-Debug'
      g++ -c -pipe -fno-keep-inline-dllexport -g -frtti -Wall -Wextra -fexceptions -mthreads -DUNICODE -I..\libusbtest -I"C:\libusb\MinGW32\static" -I"." -I"........\5.3\mingw482_32\mkspecs\win32-g++" -o debug\main.o ..\libusbtest\main.cpp
      g++ -Wl,-subsystem,console -mthreads -o debug\libusbtest.exe debug/main.o
      debug/main.o: In function main': C:\Qt\Projects\OPVCon\libusbtest\build-libusbtest-Desktop_Qt_5_3_MinGW_32bit-Debug/../libusbtest/main.cpp:16: undefined reference to libusb_hotplug_deregister_callback@8'
      collect2.exe: error: ld returned 1 exit status
      Makefile.Debug:77: recipe for target 'debug\libusbtest.exe' failed
      mingw32-make[1]: *** [debug\libusbtest.exe] Error 1
      mingw32-make[1]: Leaving directory 'C:/Qt/Projects/OPVCon/libusbtest/build-libusbtest-Desktop_Qt_5_3_MinGW_32bit-Debug'
      Makefile:34: recipe for target 'debug' failed
      mingw32-make: *** [debug] Error 2
      17:39:35: The process "C:\Qt\Tools\mingw482_32\bin\mingw32-make.exe" exited with code 2.
      Error while building/deploying project libusbtest (kit: Desktop Qt 5.3 MinGW 32bit)
      When executing step 'Make'


      I have read just about everything on the web related to this but cannot get it right.

      What am I doing wrong?

      1 Reply Last reply Reply Quote 0
      • K
        kshots last edited by

        While I don't use qmake (I use cmake), I can tell you what your problem is. You are giving Qt the path to the library, but failing to instruct it to include the library. Essentially, you need to trigger not only a -L parameter to gcc, but also a "-l" parameter (in this case, -lusb-1.0). Figure out which qmake parameter to tweak to generate the proper "-l" out of gcc, and you should be good to go.

        1 Reply Last reply Reply Quote 0
        • First post
          Last post