I keep getting these errors:
error LNK2005: _main already defined in main.obj
error LNK2019: unresolved external symbol _SDL_main referenced in function _main_utf8
error LNK1120: 1 unresolved externals
when building this
#include <stdio.h>
#include <SDL.h>
int main(int argc, const char* argv[]){
printf("Hi\n");
return 0;
}
I've set up the directories and the linker in Visual Studio 2013, but I can't figure out what went wrong. I'm using the 32 bit SDL runtime library. I'm also fairly new to C++.
-
2Possible duplicate of Why SDL defines main macro?Chris Beck– Chris Beck2016年05月28日 20:17:30 +00:00Commented May 28, 2016 at 20:17
1 Answer 1
Before your main function, define
#define SDL_MAIN_HANDLED
This stops SDL's "service" of parsing the command line for you(only on windows). Though this is a fix, this isn't good for cross platform programs. The other fix is to change main so that it looks like this:
int main(int argc, char* argv[])
You must do this because of the main macro defined in SDL_Main.h that forces you to have exactly that otherwise it will give you the error you have.