main.obj : error LNK2019: unresolved external symbol __imp__MessageBoxA@16 referenced in function _WinMain@16 RRS feed

  • Question

  • ------ Build started: Project: HelloWorld, Configuration: Debug Win32 ------




    main.obj : error LNK2019: unresolved external symbol __imp__MessageBoxA@16 referenced in function _WinMain@16

    C:\Documents and Settings\Administrator\Desktop\dev Projects\HW\HelloWorld\Debug\HelloWorld.exe : fatal error LNK1120: 1 unresolved externals

    Build log was saved at "file://c:\Documents and Settings\Administrator\Desktop\dev Projects\HW\HelloWorld\HelloWorld\Debug\BuildLog.htm"

    HelloWorld - 2 error(s), 0 warning(s)

    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

    Please bear in mind that I'm *very* much a newbie to much any form of programming.  Maybe someone can help me out a little.

    The above is the output from Build as I try to compile the following code:

    #include <windows.h>

    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lcCmdLine, int nShowCmd)


    MessageBox(NULL, "All your base are belong to us!", "Hello World", MB_OK | MB_ICONEXCLAMATION);

    return 0;



    Can anyone tell me what is wrong?

    Monday, December 4, 2006 5:46 AM


All replies

  • Can you make sure that your program is linking with user32.lib.


    Monday, December 4, 2006 6:40 AM
  • exactly how do we do this?
    Tuesday, October 23, 2007 2:40 PM
  • *Clearing Throat*

    Code Block

    #pragma comment(lib,"user32.lib");

    Just enter that under your windows.h include command.

    Hope I am not to late for this awnser. Smile
    • Proposed as answer by mjkort Wednesday, July 2, 2008 10:10 AM
    Friday, November 23, 2007 5:40 AM
  • Just wanted to say that I found this solution worked for exactly the same problem I had (link error) but I was wondering whether this is the "proper" solution? Aren't we just making a workaround with this pragma? What exactly does it do, anyway? Why does this work rather than setting the libraries in the paths for the compiler (and hence, presumably, the linker)?

     For more sophisticated programs, are we going to need to define similar pragma lines for each other library we may need to link against?

     ANd just quickly, the terminating semicolon isn't required, perhaps you were thinking of pascal?
    Wednesday, July 2, 2008 10:18 AM
  • Instead of #pragma, one can as well give the library name in the linker's command. 

    LINK /out:HelloWorld.exe Main.obj User32.LIB

    The last two arguments - Main.obj and User32.LIB are the inputs to the linker. 

    If you're using Visual Studio IDE, this will be included in the default settings. Open up Project Properties. Go to Configuration Properties -> General. On the right pane, see that the "Use of MFC" is set to "Use Standard Windows Libraries". That will add all default windows libraries, including user32.dll, in the linker's command. Or, if you do not want to change it, you may also set it in the Linker properties. Go to Linker -> Input, and add "user32.lib" in the "Additional Dependencies". Before building the project, ensure that the Linker command has "user32.lib" as an input. This can be verified from Project Properties. Go to Linker->Command Line, and verify that user32.lib is in the command. 


    Monday, July 12, 2010 9:47 PM
  • It seems like many people are looking for this answer in Visual C++ 2010 Express, etc., so this is what I have found.  When you create a new project, by default SOME of the Windows standard libraries are linked, but not all of them, even if you have selected Use Standard Windows Libraries.


    To ensure you have all of them (which includes MessageBoxEx), click Configuration Properties => Linker => Input => Additional Dependencies.  Click <Edit...> then check Inherit from parent or project defaults and then OK.  Once you do that, you should see the user32.lib file listed, as well as a few others.


    Noji Ratzlaff

    Tuesday, September 27, 2011 8:55 PM
  • This is not the nicest way to do it but it is probably because you are using a console application.

    btw. should be #pragma comment(lib,"user32.lib") without ';'

    Asaf Shelly [Microsoft MVP, Intel Black-Belt]

    Thursday, March 14, 2013 2:17 AM
  • thank you :)
    Saturday, June 15, 2019 8:34 AM