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>
3
  • Also interesting Why SDL defines main macro?
    – MicroVirus
    Jul 7, 2014 at 22:52
  • This question is already answered here
    – MicroVirus
    Jul 7, 2014 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 8, 2015 at 19:36

1 Answer 1

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.

1
  • 2
    Also, it's important that Character Set be configured to Use Multi-Byte Character Set. Jan 5, 2015 at 19:57