Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » [A4] undefined reference to `WinMain@16' ONLY in Debug mode

Credits go to Matthew Leverton for helping out!
This thread is locked; no one can reply to it. rss feed Print
[A4] undefined reference to `WinMain@16' ONLY in Debug mode
Neil Roy
Member #2,229
April 2002
avatar

I recently started work on an old game which works, but has a bug I am trying to track down.

I'm using Allegro 4 with MinGW and CodeBlocks.

I enabled debug mode, linked the appropriate alleg44-debug etc... the game compiles up just fine in normal (release) mode, but when I tell CodeBlocks to compile it in debug mode I get this error. I know normally this means I'm missing END_OF_MAIN() but in this case I am not. I would post my code but there is FAR too much of it.

the end of my main looks like:

like I said, it compiles and runs fine when not in debug mode. The only difference between release and debug is it links the allegro debug library and I enable debug symbols. Otherwise, the rest of the settings are the same.

Strange error, I didn't want to work on this again in the first place, but the bug causes my game to freeze up totally and I have to use task manager to shut it down, so I need to use debug mode and track this if possible. <sigh>

Any help would be appreciated.

---
“I love you too.” - last words of Wanda Roy

Matthew Leverton
Supreme Loser
January 1999
avatar

Make sure the debug profile is also using the /subsystem:windows linker option.

Edit: that's for MSVC. Similar thing might apply to you.

Edit 2: Actually that doesn't make any sense since it is looking for WinMain but cannot find it.

The related things would be:

  • END_OF_MAIN() isn't used (it should be)

  • ALLEGRO_USE_CONSOLE is defined (it shouldn't be)

  • ALLEGRO_NO_MAGIC_MAIN is defined (it shouldn't be)

Neil Roy
Member #2,229
April 2002
avatar

the MinGW32 command is "--subsystem,windows" by the way, didn't help, but could be useful to know in the future.

I have END_OF_MAIN() properly, I don't use those other two. Like I said, it compiles just fine in release mode, but when I switch to debug mode I get that. Doesn't make any sense at all.

I'll keep at it and let you know if I come up with something...

---
“I love you too.” - last words of Wanda Roy

Matthew Leverton
Supreme Loser
January 1999
avatar

You can easily see if it's an END_OF_MAIN problem by just hardcoding it:

      int __stdcall WinMain(void *hInst, void *hPrev, char *Cmd, int nShow)  
      {                                                                      
         return _WinMain((void *)_mangled_main, hInst, hPrev, Cmd, nShow);   
      }

Requires you to rename your "main" function to "_mangled_main".

Neil Roy
Member #2,229
April 2002
avatar

Why would that be an END_OF_MAIN() problem if it compiles just fine when not in debug mode though? If it was an END_OF_MAIN() problem it should give me the same error regardless of which mode I compile it for.

I'll try that out, but I'm certain that is not the problem.

Same error... here's the exact error, perhaps this will shine more light on the problem:

c:\users\neil\develop\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\libmingw32.a(main.o):main.c|| undefined reference to `WinMain@16'|

Wait a sec... I think I see the problem... where in hell is it getting a main.c from??? I don't have a main.c in my project. >=( <bangs head against wall>

EDIT: okay, I solved the problem by deleting the DEBUG build options and recreating a new DEBUG build by copying the release version and renaming it DEBUG, then changing a few settings specifically to debugging and it works. I originally just created a debug build then done all the settings. Although they all LOOKED correct, obviously something was amiss... who knows... strange and I wish I knew what it was, but it works anyhow. It was some screwy compiler setting...

---
“I love you too.” - last words of Wanda Roy

Go to: