SDL and WinMain() (GCC) [FIXED]

Programming, for all ages and all languages.
Post Reply
earlz
Member
Member
Posts: 1546
Joined: Thu Jul 07, 2005 11:00 pm
Contact:

SDL and WinMain() (GCC) [FIXED]

Post by earlz »

I have tried making a simple AI thingy and used SDL for a display, but I'd like to be able to use the console window...well I get an undefined reference to WinMain if I include mingw32, then this error disappears(and I can't just do -lSDL I have to do -lSDLmain and -lSDL.dll)

but if I don't have main() then I get undefined reference to SDL_main..so what the crap is with this!?

and then when I include all those libraries,(only iostream, cstdlib, and SDL.h are included) the console window will be there, but it won't let me print anything to it..I have tried printf, cout, and fprintf(stderr,"bah") but nothing works!

edit:
Well I figured out the console window problems came back to -lmingw32 and I fixed the undefined reference created by using this code

Code: Select all

#ifdef WIN32 //This will overcome the bugs with MingW and GCC
int main(int argc,char**v){}

//int SDL_main(int t,char **v){}

extern "C" int WINAPI WinMain(
    HINSTANCE hInstance,
    HINSTANCE hPrevInstance,
    LPSTR lpCmdLine,
    int nCmdShow
)
#else
int main(int argc,char **argv)
#endif
{
//code follows..
not very pretty, but it works and is portable..
and my makefile command came down to

Code: Select all

	g++ $(_CFLAGS) -c main.cpp -o obj/main.o

	g++  $(_OBJS) -lSDL -o Robots_AI.exe
(ld doesn't work for some reason..it's like it doesn't link with the standard library cause I get undefined symbols for strings and cout and such...)
User avatar
jhawthorn
Member
Member
Posts: 58
Joined: Sun Nov 26, 2006 4:06 pm
Location: Victoria, BC, Canada
Contact:

Post by jhawthorn »

To fix "Undefined reference to WinMain" you should have used -mwindows.
Post Reply