Search code examples
c++program-entry-pointlnk2019

Unresolved External _main in a console application


I have the following main function:

int main(int argv, char** argc) {
MainGame mainGame;
mainGame.run();

system("pause");
return 0;
}

it throw a LNK2019 unresolved _main at me.

now i did a bit of google-ing and found countless examples of people having accidentlyt setup win32 applications instead of the intended console app, so I checked mine in linker->system->subsystem and it read console.


Solution

  • Had a similar problem when using SDL. I've added #undef main after #include "SDL.h" since main was defined inside SDL for some other purpose (as DimChtz pointed out in the comments). It solved the problem.

    By the way, this does not have to be SDL-specific. Some other included header or source file in your project could also be #define-ing "main", which would trigger this behavior.