4

I am programming SDL in C++ and I keep getting an error:

    error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup

What can I do to resolve this? Here is my source:

#include <SDL.h>
int main(int argc, char *argv[]){
    SDL_Init(SDL_INIT_VIDEO);
    SDL_Window* Window = NULL;
    Window = SDL_CreateWindow("Render Window",0,0,1000,1000, SDL_WINDOW_SHOWN || SDL_WINDOW_FULLSCREEN);
    return 0;
}

My linker and compiler seem fine, I have included console in the subsystem etc. But the error only occurs when I add:

#include <SDL.h>
  • Also interesting [Why SDL defines main macro?](http://stackoverflow.com/questions/11976084/why-sdl-defines-main-macro) – MicroVirus Jul 07 '14 at 22:52
  • This question is already answered [here](http://stackoverflow.com/questions/6847360/error-lnk2019-unresolved-external-symbol-main-referenced-in-function-tmainc) – MicroVirus Jul 07 '14 at 23:03
  • I'm not sure why you've decided to get into an edit war with yourself, but I'm locking this post. – Taryn May 08 '15 at 19:36

1 Answers1

10

I think "SDL.h" internally includes "SDL_main.h", which contains a weird #define:

#define main SDL_main

which is almost certainly screwing up your own main.

Try adding #undef main after include "SDL.h", e.g.:

#include <SDL.h>
#undef main

Since you said you have already changed SubSystem to Console, that should be all you need.

See this question for more information.

Community
  • 1
  • 1
djikay
  • 10,450
  • 8
  • 41
  • 52