Search code examples
cwinapipelles-c

<windows.h> functions trigger POLINK error in Pelles C


I have a simple program (program.c) that I am compiling with Pelles C:

#include <windows.h>
void main() {
    char buffer[256];
    GetKeyboardState(buffer);
}

When I try to compile this program, after enabling Microsoft Extensions, it fails:

Building program.obj.
Building program.exe.
POLINK: error: Unresolved external symbol '__imp_GetKeyboardState'.
POLINK: fatal error: 1 unresolved external(s).
*** Error code: 1 ***
Done.

How can I make this work?


Solution

  • The error is from POLINK: the linker. This suggests that the program needs to be linked to a library that it is not being linked to. The documentation page for GetKeyboardState says that the required library in this case is User32.lib.

    To link to the library, click "Project" -> "Project options...", then select the "Linker" tab. There will probably be libraries in the "Library and object files:" box; add the library (e.g. User32.lib, case insensitive) to this space-separated list.

    Your program should now compile.