gpt4 book ai didi

c++ - Visual Studio 2010 C++ - 未解析的外部符号

转载 作者:太空狗 更新时间:2023-10-29 21:24:19 33 4
gpt4 key购买 nike

我正在尝试使用库 HID API 进行一些 USB 编程.以下是我的代码

#include <stdio.h>
#include <stdlib.h>
#include <wchar.h>
#include <hidapi.h>


int main(int argc, char* argv[])
{
int res;
unsigned char buf[65];
#define MAX_STR 255
wchar_t wstr[MAX_STR];
hid_device *handle;
int i;

// Enumerate and print the HID devices on the system
struct hid_device_info *devs, *cur_dev;

devs = hid_enumerate(0x0, 0x0);
cur_dev = devs;
while (cur_dev) {
printf("Device Found\n type: %04hx %04hx\n path: %s\n serial_number: %ls",
cur_dev->vendor_id, cur_dev->product_id, cur_dev->path, cur_dev->serial_number);
printf("\n");
printf(" Manufacturer: %ls\n", cur_dev->manufacturer_string);
printf(" Product: %ls\n", cur_dev->product_string);
printf("\n");
cur_dev = cur_dev->next;
}
hid_free_enumeration(devs);

}

我已将以下内容添加到 Project properties->Configuration Properties->VC++ Directories->Include Directories

C:\Users\yohan\Documents\HIDApi\windows
C:\Users\yohan\Documents\HIDApi\hidapi
C:\Users\yohan\Documents\HIDApi\libusb

当我运行我的代码时,出现以下错误

Error   6   error LNK2019: unresolved external symbol _hid_free_enumeration referenced in function _main    c:\Users\yohan\documents\visual studio 2010\Projects\USB_Test\USB_Test\FirstTest.obj    USB_Test
Error 7 error LNK2019: unresolved external symbol _hid_enumerate referenced in function _main c:\Users\yohan\documents\visual studio 2010\Projects\USB_Test\USB_Test\FirstTest.obj USB_Test
Error 8 error LNK1120: 2 unresolved externals c:\users\yohan\documents\visual studio 2010\Projects\USB_Test\Debug\USB_Test.exe USB_Test

为什么我会收到这个错误?我正在使用 Visual Studio 2010 专业版。

最佳答案

您已经包含了 header ,因此编译器知道所有符号声明(函数等)。但是,链接器需要将您对这些符号的使用链接到它们的实际定义——但它找不到它们(因此出现错误)。

这可能是由多种原因引起的,但在你的情况下,你似乎没有构建库,或者如果你构建了(或者你有预构建的版本),你还没有链接它在(这就是库路径目录的用途——您需要 add the .lib file as input to the linker,添加它将搜索该 .lib 的库路径)。

在 .lib 文件中链接的另一种方法是通过特定于编译器的(在本例中为 MSVC)#pragma 指令:

#pragma comment(lib, "thelibrary.lib")

关于c++ - Visual Studio 2010 C++ - 未解析的外部符号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16486934/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com