1

我尝试开发一个Qt GUI应用程序,它将使用 USB 与板进行通信。我使用的库是libusb-win32 v1.2.5.0

当我编译应用程序时,出现以下错误:

./debug/thread_usb_comm.o:在函数“ZN15thread_usb_comm15find_usb_deviceEtt”中:

thread_usb_comm.cpp:15: 未定义引用‘usb_find_busses’
thread_usb_comm.cpp:16: 未定义引用‘usb_find_devices’
thread_usb_comm.cpp:18: 未定义引用‘usb_get_busses’
thread_usb_comm.cpp:26: 未定义引用‘usb_open’

collect2: ld 返回 1 退出状态
mingw32-make[1]: [debug/CALSYS11_calib_app.exe] 错误 1
​​mingw32-make: [debug] 错误 2

申请代码为:

(头文件)

#ifndef THREAD_USB_COMM_H
#define THREAD_USB_COMM_H

#include <QThread>
#include <QtDebug>
#include "CALSYS11.h"
#include <lusb0_usb.h>

class thread_usb_comm : public QThread
{
    Q_OBJECT

public:
    thread_usb_comm();

private:
    bool device_connected;
    usb_dev_handle *p_usb_device;

    bool find_usb_device(
       unsigned short vendor_id,
       unsigned short product_id
    );
};

#endif // THREAD_USB_COMM_H

(源文件)

#include "thread_usb_comm.h"

thread_usb_comm::thread_usb_comm()
{
    device_connected = false;
}

bool thread_usb_comm::find_usb_device(
    unsigned short vendor_id,
    unsigned short product_id
)
{
    struct usb_bus *bus;
    struct usb_device *dev;
    usb_find_busses();
    usb_find_devices();

    for (bus = usb_get_busses(); bus; bus = bus->next)
    {
        for (dev = bus->devices; dev; dev = dev->next)
        {
            if ((dev->descriptor.idVendor == vendor_id) &&
                (dev->descriptor.idProduct == product_id))
            {
                qDebug ("Device found");
                p_usb_device = usb_open(dev);
                if (0 == p_usb_device)
                {
                    qCritical ("Could not open USB device");
                    return false;
                }
                device_connected = true;
                return true;
            }
        }
    }

    qDebug ("Cannot find specified device");
    return false;
}

我在 .pro 文件中添加了指向 libusb 库的链接:

LIBS += -L\path\to\libusb-win32\lib\gcc -lusb

我在Windows 7上开发。

谢谢你,
约翰

4

1 回答 1

0

尝试构建发布而不是调试或静态库与编译器版本不兼容(当我尝试使用 MinGW 4.4 构建旧的静态库时遇到同样的问题)

于 2011-10-12T23:03:53.613 回答