Code::Blocks Forums

User forums => Help => Topic started by: SplinterOfChaos on January 05, 2008, 08:43:42 am

Title: C::B+SDL+undefined reference to 'WinMain@16'
Post by: SplinterOfChaos on January 05, 2008, 08:43:42 am
I was having an unbelievable time making my hard work compatible with computers other than the one it was compiled on with Visual Studio 9, so I thought I'd try the only attractive alternative. I just hope it's not taboo to make your first post a trouble shooting one here--but it's not likely I'll ever use this forum as more anyway.

I got my code to compile fine except this error:
mingw\lib\lib... undefined reference to 'WinMain@16'

Completely out of my hands. It registered all the right files, knew where to find them, knew what to do with them, why the hell did this happen? I'll give any info you guys think would be helpful to solve this problem.
Title: Re: C::B+SDL+undefined reference to 'WinMain@16'
Post by: wobien on January 05, 2008, 02:28:15 pm
You have to enable full command-line logging in the build log (Settings->Compilor and Debugger->Other Settings (last tab)).
Then post the resulting build log.
Title: Re: C::B+SDL+undefined reference to 'WinMain@16'
Post by: mandrav on January 05, 2008, 03:31:55 pm
I was having an unbelievable time making my hard work compatible with computers other than the one it was compiled on with Visual Studio 9, so I thought I'd try the only attractive alternative. I just hope it's not taboo to make your first post a trouble shooting one here--but it's not likely I'll ever use this forum as more anyway.

I got my code to compile fine except this error:
mingw\lib\lib... undefined reference to 'WinMain@16'

Completely out of my hands. It registered all the right files, knew where to find them, knew what to do with them, why the hell did this happen? I'll give any info you guys think would be helpful to solve this problem.

Have you read the SDL article (http://wiki.codeblocks.org/index.php?title=Using_SDL_with_Code::Blocks) on our wiki? It's a bit dated but I doubt it has become invalid.
Specifically, check if you link to mingw32, SDL, and SDLmain libraries.
Title: Re: C::B+SDL+undefined reference to 'WinMain@16'
Post by: SplinterOfChaos on January 05, 2008, 08:26:37 pm
That's how I got it to work in the first place.

It won't let me copy the contents to the clipboard still, but nothing has changed.
Title: Re: C::B+SDL+undefined reference to 'WinMain@16'
Post by: thomas on January 05, 2008, 11:14:08 pm
I forgot what exactly was the cause/solution for this (having not used SDL for a loooooooooooong time), but it is a pretty well-known problem (or rather, feature). It has to do with the library's own main function and the defined preprocessor constants (which determine whether or not it implements one).

As far as I remember, there's just one preprocessor constant that you need to set, and it works fine. Look on the SDL site, there are a couple of similar issues and solutions to them.
Title: Re: C::B+SDL+undefined reference to 'WinMain@16'
Post by: Albenejean on January 05, 2008, 11:20:02 pm
http://www.libsdl.org/faq.php?action=listentries&category=4#58 (http://www.libsdl.org/faq.php?action=listentries&category=4#58)
Title: Re: C::B+SDL+undefined reference to 'WinMain@16'
Post by: SplinterOfChaos on January 06, 2008, 12:19:08 am
So where is it I paste "-lmingw32 -lSDLmain -lSDL -mwindows" (assuming I understood).

I tried putting it in compiler and settings->global compiler settings->toolchain executables->program files: c++ compiler (after the "mingw32-g++.exe"), but it didn't work.

EDIT
Got it. Needed to put it there, except at the linker box.
Title: Re: C::B+SDL+undefined reference to 'WinMain@16'
Post by: Albenejean on January 06, 2008, 12:29:07 am
Quote
I tried putting it in compiler and settings->global compiler settings->toolchain executables->program files: c++ compiler (after the "mingw32-g++.exe"), but it didn't work.

EDIT
Got it. Needed to put it there, except at the linker box.

No, no... Poject->Build options->Linker and add SDLmain and SDL. And don't forget to tell your compiler where the files are located.
Title: Re: C::B+SDL+undefined reference to 'WinMain@16'
Post by: SplinterOfChaos on January 06, 2008, 01:22:36 am
I'd already done all that.

But it worked so I don't care! In fact, my product worked on someone else's computer EASILY and without the full week of debugging that Visual C++ took, and unsuccessfully!