The SDL forums have moved to discourse.libsdl.org.
This is just a read-only archive of the previous forums, to keep old links working.


SDL Forum Index
SDL
Simple Directmedia Layer Forums
"multiple definition of `main'" when compiling app
Kyle Noteboom
Guest

I'm trying to compile a simple application which consists of initializing SDL, and then shutting down.
The compiler I'm using is MinGW w64: x86_64-4.9.1-posix-seh-rt_v3-rev1.7
The meat of the error CLion spits out is this:

D:\Programming\Projects\CLion\OpenGL\Libraries\SDL2-2.0.3\lib\x64\SDL2main.lib(./x64/Release/SDL_windows_main.obj)Sad.text[main]+0x0): multiple definition of `main'
D:/Software/Programs/MinGW/w64/x86_64-4.9.1-posix-seh-rt_v3-rev1.7/bin/../lib/gcc/x86_64-w64-mingw32/4.9.1/../../../../x86_64-w64-mingw32/lib/../lib/libmingw32.a(lib64_libmingw32_a-crt0_c.o):crt0_c.cSad.text.startup+0x0): first defined here

I've made a Gist containing my code, the build log, CMakeLists.txt and FindSDL2.cmake here: https://gist.github.com/anonymous/5c4b9c2c42a4e3db4357

What can I do to get this to compile? Am I using a wrong version of MinGW w64? Or am I not linking correctly?
"multiple definition of `main'" when compiling app
Sik


Joined: 26 Nov 2011
Posts: 905
Gonna be blunt: I never got SDL_main to work with MinGW-w64. However,
MinGW (and MinGW-w64 in turn) can cope with using main instead of
WinMain just fine, so in this case the solution would be to #undef
main and then don't link SDL_main in the first place.

That said, first make sure that SDL's header is included, because
that's the one that redefines your main into something else (otherwise
you'll have two main functions).
_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org