Thread: error LNK2019: unresolved external symbol __imp__GetKeyState@4

  1. #1
    Algorithm engineer
    Join Date
    Jun 2006
    Posts
    286

    error LNK2019: unresolved external symbol __imp__GetKeyState@4

    Hi, I have written a C++ program, which I have previously compiled with MinGW. However, due to tricky circumstances (MinGW doesn't handle Boost very well apparently), I had to change to Visual Studio. The project compiles perfectly, except from one row, which calls the function GetKeyState located in windows.h. If I include that line in my code, I get the following compilation result:

    Code:
    ------ Build started: Project: user_interface, Configuration: Release Win32 ------
    Performing Makefile project actions
    QFileInfo::absolutePath: Constructed with empty filename
    Microsoft (R) Program Maintenance Utility Version 9.00.21022.08
    Copyright (C) Microsoft Corporation.  All rights reserved.
     "c:\Program Files\Microsoft Visual Studio 9.0\VC\bin\nmake.exe" -f Makefile.Debug
    Microsoft (R) Program Maintenance Utility Version 9.00.21022.08
    Copyright (C) Microsoft Corporation.  All rights reserved.
     cl -c -nologo -Zm200 -Zc:wchar_t- -Zi -MDd -GR -EHsc -W3 -w34100 -w34189 -DUNICODE -DWIN32 -DQT_LARGEFILE_SUPPORT -DQT_DLL -DQT_GUI_LIB -DQT_CORE_LIB -DQT_THREAD_SUPPORT -I"c:\Program1\Qt\2010.02.1\qt\include\QtCore" -I"c:\Program1\Qt\2010.02.1\qt\include\QtGui" -I"c:\Program1\Qt\2010.02.1\qt\include" -I"." -I"c:\Program1\Qt\2010.02.1\qt\include\ActiveQt" -I"debug" -I"c:\Program1\Qt\2010.02.1\qt\mkspecs\default" -Fodebug\ @C:\Users\KRISTO~1\AppData\Local\Temp\nmD695.tmp
    user_interface.cpp
     link /LIBPATH:"c:\Program1\Qt\2010.02.1\qt\lib" /NOLOGO /DEBUG /MANIFEST /MANIFESTFILE:"debug\user_interface.intermediate.manifest" /SUBSYSTEM:WINDOWS "/MANIFESTDEPENDENCY:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' publicKeyToken='6595b64144ccf1df' language='*' processorArchitecture='*'" /OUT:debug\user_interface.exe @C:\Users\KRISTO~1\AppData\Local\Temp\nmEAB3.tmp 
    LINK : debug\user_interface.exe not found or not built by the last incremental link; performing full link
    user_interface.obj : error LNK2019: unresolved external symbol __imp__GetKeyState@4 referenced in function "unsigned char __cdecl get_key_down(int)" (?get_key_down@@YAEH@Z)
    debug\user_interface.exe : fatal error LNK1120: 1 unresolved externals
    NMAKE : fatal error U1077: '"c:\Program Files\Microsoft Visual Studio 9.0\VC\bin\link.EXE"' : return code '0x460'
    Stop.
    NMAKE : fatal error U1077: '"c:\Program Files\Microsoft Visual Studio 9.0\VC\bin\nmake.exe"' : return code '0x2'
    Stop.
    Project : error PRJ0019: A tool returned an error code from "Performing Makefile project actions"
    Build log was saved at "file://d:\Work\TSEA27_(Elektronikprojektet)\Projektet\src\user_interface_visual_studio\user_interface\Release\BuildLog.htm"
    user_interface - 5 error(s), 0 warning(s)
    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
    "user_interface.obj : error LNK2019: unresolved external symbol __imp__GetKeyState@4 referenced in function "unsigned char __cdecl get_key_down(int)" (?get_key_down@@YAEH@Z)"
    This is probably a beginner problem, but what is causing it and how do I solve it? If I have to include some library to make it work, how do I do that and where is the library located?
    Come on, you can do it! b( ~_')

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    MSDN tells you what library it's in. You'll need to go to project options, compiler and linker, to add libraries IIRC.

  3. #3
    Algorithm engineer
    Join Date
    Jun 2006
    Posts
    286
    Adding the path to the library to the dependency path didn't make any difference.

    Normal Win32 Console Applications that use GetKeyState can be compiled, and they could before I added the path to the dependency paths to (which I found out).

    Makefile Projects that uses GetKeyState on the other hand, can't be compiled, there the compiler will give an error corresponding to: "main.obj : error LNK2019: unresolved external symbol __imp__GetKeyState@4 referenced in function _main". Why I don't know.

    My program is a Makefile Project, and I can't compile it, although I think I should be able to.
    Last edited by TriKri; 05-09-2010 at 07:58 PM.
    Come on, you can do it! b( ~_')

  4. #4
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    I have never worked with makefiles, but MSDN says it's in user32.lib. So you can't go to C/C++ -> Linker -> Input -> and enter user32.lib?
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  5. #5
    Algorithm engineer
    Join Date
    Jun 2006
    Posts
    286
    The problem has already been resolved. No, there is no such thing in VS Makefile Projects, there you simply have to add the libraries and the dependency paths directly into your makefile.

    The thing that caused the problem in my case, was that I was building a Qt project, and let qt generate the makefiles for me from a .pro file (qt project file), with a program called qmake. The generated makefiles then contained something that visual studio didn't like, or at least treated differently than MinGW. The solution to the problem was to change in my .pro file, and add "LIBS += User32.Lib", in order to tell qmake to generate the appropriate makefiles.

    -Kristofer
    Come on, you can do it! b( ~_')

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 03:07 AM
  2. C++ std routines
    By siavoshkc in forum C++ Programming
    Replies: 33
    Last Post: 07-28-2006, 12:13 AM
  3. Including lib in a lib
    By bibiteinfo in forum C++ Programming
    Replies: 0
    Last Post: 02-07-2006, 02:28 PM
  4. Stupid compiler errors
    By ChrisEacrett in forum C++ Programming
    Replies: 9
    Last Post: 11-30-2003, 05:44 PM
  5. debug to release modes
    By DavidP in forum Game Programming
    Replies: 5
    Last Post: 03-20-2003, 03:01 PM

Tags for this Thread