views:

538

answers:

3

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.

+2  A: 

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.

DavidK
Yes, I already tracked down those potential issues and I'm linking against User32.lib, advapi32.lib, etc. That didn't seem to help. I'm thinking there is some kind of issue with VC++ trying to link C code, though I can't imagine why.
ceretullis
Have you checked the order, so that user32.lib comes after PDCurses.lib?
DavidK
Yeah, I started playing around with the order when I found the mis-spelling.
ceretullis
+1  A: 

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.

Jonathan Leffler
Yes, built on the same machine with the same compiler. There are 11 total undefined reference errors (same Error Code different symbols).
ceretullis
A: 

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.

ceretullis