First up, I'm new to C++ (and MS VS), so I'm very probably missing something here. I do have some coding experience, though, and I'm having trouble discerning what might be escaping me.
I'm trying to use Logitech supplied .lib and .h files to control a G13 keyboard, by using the following code:
[Edit: This code, and error messages, has been altered to take into account points below from Mike Vine and Hans Passant (thanks guys!), but the issue still remains]
#include "pch.h"
#include <iostream>
#pragma comment(lib,"LogitechLCDLib")
#include "Include\LogitechLCDLib.h"
int main()
{
wchar_t str[] = L"Hello";
LogiLcdInit(str, 1);
return 0;
}
However, I receive the following errors;
Error LNK2019 unresolved external symbol "bool __cdecl LogiLcdInit(wchar_t *,int)" (?LogiLcdInit@@YA_NPAGH@Z) referenced in function _main ConsoleApplication1 C:\Users\clewl\source\repos\ConsoleApplication1\ConsoleApplication1\ConsoleApplication1.obj 1
Error LNK1120 1 unresolved externals ConsoleApplication1 C:\Users\clewl\source\repos\ConsoleApplication1\Debug\ConsoleApplication1.exe 1
I've been around the houses a bit here - I initially though I was doing something wrong with wchar_t* (its new to me, as was const correctness), and then that, for some reason, the .lib wasn't being loaded.
However, I have now found the wonders of /VERBOSE (told you I was new to Visual Studio ;-) ), and have been comparing the output of my code with the (working) example supplied with the Logitech SDK.
I'm reasonably sure the .h is ok, as intellisense shows the definition, and the .lib file is being picked up correctly, as verbose build output shows lines such as
1>Starting pass 1
1>Processed /DEFAULTLIB:LogitechLCDLib
<snip>
1> Searching C:\Users\clewl\source\repos\ConsoleApplication1\ConsoleApplication1\Lib\x64\LogitechLCDLib.lib:
However, right at the end of the build output is
1> Unused libraries:
<snip>
1> C:\Users\clewl\source\repos\ConsoleApplication1\ConsoleApplication1\Lib\x64\LogitechLCDLib.lib
When I compare this with the build output from the working example, I see lines such as
1> Processed /DEFAULTLIB:LogitechLCDLib.lib
<snip>
1> LogitechLCDLib.lib(LogitechLCDLib.obj)
1> LogitechLCDLib.lib(stdafx.obj)
<snip>
1> Searching ..\..\Lib\x86\LogitechLCDLib.lib:
1> Found "bool __cdecl LogiLcdInit(wchar_t *,int)" (?LogiLcdInit@@YA_NPA_WH@Z)
1> Referenced in LCDDemoDlg.obj
1> Loaded LogitechLCDLib.lib(LogitechLCDLib.obj)
1> Found ___@@_PchSym_@00@UyfrowztvmgUdlipUyIzCIHuEBIJHIIFJUhixUhwphUoxwUoltrgvxsoxworyUivovzhvUhgwzucOlyq@9DC0ED7C20F9DB3D
1> Referenced in LogitechLCDLib.lib(LogitechLCDLib.obj)
1> Loaded LogitechLCDLib.lib(stdafx.obj)
amongst others, and no reference to LogitechLCDLib.lib being an unused library.
Unfortunately, after a fairly intensive couple of days, my google fu appears to have given up on me, and I'm unable to progress any further. There are many examples of this linker error, but none seem to fix this case - incorrect /NODEFAUTLIB, or (as in the only case I can find using this library), just moving the #pragma comment line.
And so I throw myself before your superior knowledge and experience! If any of you kind people could tell me what egregious error I am making, or fundamental concept I'm missing, I would be very thankful.
I'm a little hesitant to post the full verbose logs, but if any further information is required, I'd be more than happy to provide it.
TL;DR - Bloke who thinks he can code can't perform basic tasks, but had a good go and asked very nicely. ;-)
Thanks for Reading!
Neal