Important: Please read the Qt Code of Conduct -

HIDAPI with Qt5- compiling error

  • I am new to QT, and working with HIDAPI for Microchip Mcus. I have compiled the example code for HIDAPI and it is giving "undefined reference to 'hid_open' " error. All the source files are copied into project folder. Even then i am getting similar error for six functions that are defined in hidapi.c file. we are using Qt Creator 4.2.0 (4.2.0) Based on Qt 5.7.1.
    I have gone through related posts in Qt forum & in net, but could not find a solution. Please give clues about problem.

  • Lifetime Qt Champion

    @o6a6r9v1p "undefined reference to 'hid_open' " - means you either do not link against the library containing hid_open or you did not add the source file containing the hid_open definition to your project if you do not use the library.
    Just copying the files into your project directory doesn't mean they are built. You need to add them in your pro file (rerun qmake after changing pro file).

  • did as you told, but getting same error message.

  • @jsulm
    Thanks for your input. I did as you told.
    pro file contents looks as below:

    #begins here 
    QT       += core gui
    greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
    TARGET = HID_PnP_Demo
    TEMPLATE = app
    SOURCES += main.cpp\
            demoapp.cpp \
        hid_pnp.cpp \
    HEADERS  += demoapp.h \
        hid_pnp.h \
        hidapi.h    \
    FORMS    += demoapp.ui
    #end of file

    I am getting now the following type of error for 6 functions defined in hidapi.cpp

    C:\Users\Documents\HID_PnP_Demo\HID_PnP_Demo\hidapi.cpp:286: error: undefined reference to `_imp__SetupDiGetClassDevsA@16'

    In net, it is said to be linker/path problem. Where shall i set them?

    [edit: added coding tags three back-ticks before and after SGaist ]

  • Lifetime Qt Champion

    Hi and welcome to devnet,

    You are missing

    win32 {
       LIBS += -lhid -lsetupapi

    in your .pro file.

  • @SGaist
    Thank you and @jsulm for your quick help. Now project is compiled & I getting the GUI.

  • Lifetime Qt Champion

    Great !

    In that case please mark the thread as solved using the "Topic Tools" button so other forum users may know a solution has been found :)

Log in to reply