Author Topic: C::B+SDL+undefined reference to 'WinMain@16'  (Read 12416 times)

Offline SplinterOfChaos

  • Single posting newcomer
  • *
  • Posts: 8
C::B+SDL+undefined reference to 'WinMain@16'
« 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.

Offline wobien

  • Multiple posting newcomer
  • *
  • Posts: 69
Re: C::B+SDL+undefined reference to 'WinMain@16'
« Reply #1 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.

Offline mandrav

  • Project Leader
  • Administrator
  • Lives here!
  • *****
  • Posts: 4315
    • Code::Blocks IDE
Re: C::B+SDL+undefined reference to 'WinMain@16'
« Reply #2 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 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.
Be patient!
This bug will be fixed soon...

Offline SplinterOfChaos

  • Single posting newcomer
  • *
  • Posts: 8
Re: C::B+SDL+undefined reference to 'WinMain@16'
« Reply #3 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.

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: C::B+SDL+undefined reference to 'WinMain@16'
« Reply #4 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.
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

Offline Albenejean

  • Multiple posting newcomer
  • *
  • Posts: 65

Offline SplinterOfChaos

  • Single posting newcomer
  • *
  • Posts: 8
Re: C::B+SDL+undefined reference to 'WinMain@16'
« Reply #6 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.

Offline Albenejean

  • Multiple posting newcomer
  • *
  • Posts: 65
Re: C::B+SDL+undefined reference to 'WinMain@16'
« Reply #7 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.

Offline SplinterOfChaos

  • Single posting newcomer
  • *
  • Posts: 8
Re: C::B+SDL+undefined reference to 'WinMain@16'
« Reply #8 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!