Thread: unresolved external symbol _WinMain@16

  1. #1
    larry
    Guest

    unresolved external symbol _WinMain@16

    I'm trying to write Win32 application without using some wizard. I create a project, add a source file to it and write a wmain() function into it, nothing else. But when linking, after compilation, I always get "unresolved external symbol _WinMain@16" message. I've read in help that I have to set (in Project settings) an entry-point symbol value to "wWinMainCRTStartup" to avoid this error. Well, I don't get the message described above anymore, but I get one that's similar: "unresolved external symbol _wWinMain@16". I tried almost everything. What's wrong?

  2. #2
    Registered User Esss's Avatar
    Join Date
    Aug 2001
    Posts
    133
    For wmain, you should use wmainCRTStartup.
    Ess
    Like a rat in a maze who says,
    "Watch me choose my own direction"
    Are you under the illusion
    The path is winding your way?
    - Rush

  3. #3
    Registered User larry's Avatar
    Join Date
    Sep 2001
    Posts
    96
    One step further. Now linker reports "error LNK2001: unresolved external symbol _wmain"

  4. #4
    Registered User
    Join Date
    Sep 2001
    Posts
    156
    In the Output category of the Link field in the Project Settings dialog box, set the Entry Point Symbol to wWinMainCRTStartup.

  5. #5
    Registered User Esss's Avatar
    Join Date
    Aug 2001
    Posts
    133
    > One step further. Now linker reports "error LNK2001: unresolved external symbol _wmain"

    Well, we're going to have to see a little code, then. Bear in mind that a 'Win32 Application' expects a WinMain or wWinMain, whereas a 'Win32 Console Application' uses main or wmain. Make sure you've defined both UNICODE and _UNICODE, and not _MBCS, in the C/C++ tab.

    > In the Output category of the Link field in the Project Settings dialog box, set the Entry Point Symbol to wWinMainCRTStartup.

    If you read the post, you'll see that that's not what he wants to do.
    Ess
    Like a rat in a maze who says,
    "Watch me choose my own direction"
    Are you under the illusion
    The path is winding your way?
    - Rush

  6. #6
    Registered User larry's Avatar
    Join Date
    Sep 2001
    Posts
    96
    I'm not sure I understand, but as for some code, there is nothing, just

    Code:
    int WinMain() {
      return 0;
    }
    For me, it doesn't matter if I use main, wmain, WinMain, or wWinMain. I just want Win32 Application with this code (not Console; Win32 Console Application compiles OK) to compile. I did as you told, now my preprocessor definitions (under C/C++ tab) look like this:
    "WIN32,_DEBUG,_WINDOWS,STRICT,UNICODE,_UNICODE "
    But it still doesn't compile! I took from your explanation that I should use "wWinMainCRTStartup" entry-point symbol. So I did and now I'm where I was at the beginning - linker reports
    "LIBCD.lib(wwincrt0.obj) : error LNK2001: unresolved external symbol _wWinMain@16"
    I didn't mention a thing about the compiler yet, it's MSVC++ 5.0. Please help, I'm helpless.
    Please excuse my poor english...

  7. #7
    Registered User Esss's Avatar
    Join Date
    Aug 2001
    Posts
    133
    If you want to use WinMain, you must use

    #include <windows.h>

    wWinMain is not in windows.h, so you either need to use atlbase.h, or include the line:

    extern "C" int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nShowCmd);

    Windows Applications (linked with /subsystem:windows) do not support the entry points main or wmain.
    Ess
    Like a rat in a maze who says,
    "Watch me choose my own direction"
    Are you under the illusion
    The path is winding your way?
    - Rush

  8. #8
    Registered User larry's Avatar
    Join Date
    Sep 2001
    Posts
    96
    Well, I included windows.h header, but it doesn't even compile. Seems like it needs any other header before windows.h, doesn't it? The report looks like this:

    "
    Compiling...
    source.cpp
    d:\Program Files\DevStudio\VC\INCLUDE\winnt.h(199) : warning C4201: nonstandard extension used : nameless struct/union
    d:\Program Files\DevStudio\VC\INCLUDE\winnt.h(218) : warning C4201: nonstandard extension used : nameless struct/union
    d:\Program Files\DevStudio\VC\INCLUDE\winnt.h(4227) : warning C4201: nonstandard extension used : nameless struct/union
    d:\Program Files\DevStudio\VC\INCLUDE\winnt.h(4236) : warning C4201: nonstandard extension used : nameless struct/union
    d:\Program Files\DevStudio\VC\INCLUDE\winbase.h(481) : warning C4201: nonstandard extension used : nameless struct/union
    d:\Program Files\DevStudio\VC\INCLUDE\mmsystem.h(1623) : warning C4201: nonstandard extension used : nameless struct/union
    d:\Program Files\DevStudio\VC\INCLUDE\mmsystem.h(1627) : warning C4201: nonstandard extension used : nameless struct/union
    d:\Program Files\DevStudio\VC\INCLUDE\mmsystem.h(1648) : warning C4201: nonstandard extension used : nameless struct/union
    d:\Program Files\DevStudio\VC\INCLUDE\mmsystem.h(1652) : warning C4201: nonstandard extension used : nameless struct/union
    d:\Program Files\DevStudio\VC\INCLUDE\wtypes.h(1039) : warning C4201: nonstandard extension used : nameless struct/union
    d:\Program Files\DevStudio\VC\INCLUDE\wtypes.h(1064) : warning C4201: nonstandard extension used : nameless struct/union
    d:\Program Files\DevStudio\VC\INCLUDE\wtypes.h(1077) : warning C4201: nonstandard extension used : nameless struct/union
    d:\Program Files\DevStudio\VC\INCLUDE\oaidl.h(394) : warning C4201: nonstandard extension used : nameless struct/union
    D:\Dokumenty\cpp\pokus32\source.cpp(3) : error C2731: 'WinMain' : function cannot be overloaded
    "

    Please excuse my poor english...

  9. #9
    Registered User Esss's Avatar
    Join Date
    Aug 2001
    Posts
    133
    > Well, I included windows.h header, but it doesn't even compile

    That's because your code is wrong. Congratulations.

    > D:\Dokumenty\cpp\pokus32\source.cpp(3) : error C2731: 'WinMain' : function cannot be overloaded

    This means that you've specified the wrong arguments for WinMain. WinMain's prototype is:

    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd);

    You need to specify all these arguments in order to use WinMain.
    Ess
    Like a rat in a maze who says,
    "Watch me choose my own direction"
    Are you under the illusion
    The path is winding your way?
    - Rush

  10. #10
    Registered User larry's Avatar
    Join Date
    Sep 2001
    Posts
    96
    My code now looks like this:
    Code:
    #include <windows.h>
    
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) {
      return 0;
    }
    It still reports those "nonstandard extension used : nameless struct/union" messages! But they are only warnings, so I can start the linker. And the linker reports "LIBCD.lib(wwincrt0.obj) : error LNK2001: unresolved external symbol _wWinMain@16". And it's an error, so I can't continue...

    > That's because your code is wrong. Congratulations.

    Are you sure? Message like "d:\Program Files\DevStudio\VC\INCLUDE\winnt.h(4227) : warning C4201: nonstandard extension used : nameless struct/union" has something to do with my code? Maybe it's true. So, my question is: WHAT SHOULD MY CODE LOOK LIKE FOR CLEAR COMPILATION?? WHAT AM I DOING WRONG?? Please, tell me this, if you know it.
    Please excuse my poor english...

  11. #11
    Has a Masters in B.S.
    Join Date
    Aug 2001
    Posts
    2,263
    ok better, heres one from MSVC

    Code:
    #define WIN32_LEAN_AND_MEAN	
    #include <windows.h>
    
    int APIENTRY WinMain(HINSTANCE hInstance,
                         HINSTANCE hPrevInstance,
                         LPSTR     lpCmdLine,
                         int       nCmdShow)
    {
    
    	return 0;
    }
    are you making a win32 app or a console app?
    Last edited by no-one; 09-28-2001 at 12:13 PM.
    ADVISORY: This users posts are rated CP-MA, for Mature Audiences only.

  12. #12
    Registered User minime6696's Avatar
    Join Date
    Aug 2001
    Posts
    267

    Exclamation Well...

    Obviousley if the missing symbol is __WinMain, then you must conclude from the name:

    Win + Main = Windows Main
    That you need to base the program around WinMain. BUT I think you've doen something to your compiler...

    SPH

  13. #13
    Registered User Esss's Avatar
    Join Date
    Aug 2001
    Posts
    133
    > Are you sure?

    It was. Now your linker settings are wrong. Take out the 'Entry Point' definition.

    > It still reports those "nonstandard extension used : nameless struct/union" messages!

    It's a level 4 warning, and it can be safely ignored. If it gives you heartache, you can put

    #pragma warning(disable:4201)

    before the offending includes.
    Ess
    Like a rat in a maze who says,
    "Watch me choose my own direction"
    Are you under the illusion
    The path is winding your way?
    - Rush

  14. #14
    Registered User larry's Avatar
    Join Date
    Sep 2001
    Posts
    96
    It works. Thanx a lot.
    Please excuse my poor english...

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