-1

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?

wizzwizz4
  • 6,140
  • 2
  • 26
  • 62

1 Answers1

0

The problem here is with 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 this function says that the required library 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 User32.lib (case insensitive) to this space-separated list.

Your program should now compile.

wizzwizz4
  • 6,140
  • 2
  • 26
  • 62
  • This has been asked so many times before. I do t this k we need yet another version of this. – David Heffernan Dec 28 '16 at 12:13
  • @DavidHeffernan Thanks for marking as duplicate. I only asked this question because nothing was coming up in search results; now people who have my problem will be directed to the "original" question. – wizzwizz4 Dec 28 '16 at 12:35
  • Somewhat hard to fathom. A search for your error message yields multiple results. – David Heffernan Dec 28 '16 at 12:40
  • @DavidHeffernan None of them answered the question; at least none that I found. I worked the answer out myself (which wasn't too hard now that I know what a linker is) and posted this, after searching for duplicates (although probably not with the right keywords). – wizzwizz4 Dec 28 '16 at 12:46
  • [This post](http://stackoverflow.com/a/12574400/1889329) addresses your specific issue, and provides an answer. – IInspectable Dec 28 '16 at 13:21