How do I link PDCurses to a C++ application on Windows?
Question
I'm building a C++ application and need to use PDCurses on Windows. I'm compiling with VC++ from MS VS 2005 and I'm getting a link error.
error LNK2019: unresolved external symbol __imp__GetKeyState@4 referenced in function __get_key_count
There are 11 errors all with the same error code and different symbols. The missing symbols are __imp__MapVirtualKeyA@8, __imp__FindWindowA@8, __imp__wsprintfA, __imp__SendMessageA@16, __imp__GetWindowThreadProcessId@8, __imp__MessageBeep@4. It is almost like the VC++ can't find the appropriate ASCII implementations of these functions. I should also note that the demo programs that come with PDCurses compiled fine, though they are C programs.
In the C++ program, I include the header using
extern "C"
{
#include <curses.h>
}
I'm sure I'm forgetting to link against some C standard library, but I'm not sure which one.
Solution
GetKeyState() is a Windows function in "user32.dll", so you need to be sure you're linking against "user32.lib". You may also need to make sure it comes after the PDCurses library in the list of linker libraries, too.
OTHER TIPS
Did you build PDCurses on your machine - with MS VC++? If so, I'm not sure what's up. If not, then there's a decent chance that what you are using is not compatible with MS VC++. Mixing code from different C++ compilers is fraught. It also depends a bit on what you mean by 'several other errors'. If that's a grotesque understatement for 'hundreds of errors', then that is likely the trouble. If you have just a few (say another half dozen or fewer) similar errors, then it is less likely to be the trouble.
Okay, I figured this out ;) I'm building with scons, I was including user32.lib with a variable USER32_LIB
, which defaults to an empty string except on windows where it gets defined to user32.lib. In the windows section, I had a typo, I had USER32_LIb
rather than USER32_LIB
.