1

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++.

Flexo
  • 87,323
  • 22
  • 191
  • 272
Thomas
  • 11
  • 2
  • 2
    Possible duplicate of [Why SDL defines main macro?](http://stackoverflow.com/questions/11976084/why-sdl-defines-main-macro) – Chris Beck May 28 '16 at 20:17

1 Answers1

2

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.

xXCoolinXx
  • 361
  • 5
  • 15