Reputation: 23035
I am trying to do some USB programming using the library HID API. Following is my code
#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);
}
I have added following into the 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
When I run my code, I get the following error
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
Why I am getting this error? I am using Visual studio 2010 professional.
Upvotes: 3
Views: 3408
Reputation: 23035
I have to include their complete visual C++ project into my project. Then the issue is gone
Upvotes: 0
Reputation: 98816
You've included the headers, so the compiler knows about all the symbol declarations (functions, etc). But, the linker needs to link your usages of these symbols to their actual definitions -- and it can't find them (hence the error).
This can be caused by a variety of things, but in your case it looks like you haven't built the the library, or if you did (or you have a pre-built version), you haven't linked it in (that's what the Library Path directories are for -- you need to add the .lib file as input to the linker, add it will search the library paths for that .lib).
Another way to link in a .lib file is via a compiler-specific (MSVC-only, in this case) #pragma
directive:
#pragma comment(lib, "thelibrary.lib")
Upvotes: 3