0

I've been working on the prototypes of an app that makes use of SDL and winsock libraries when I was suddenly met with this error on compilation:

LNK2019 unresolved external symbol main referenced in function "int __cdecl invoke_main(void)" (?invoke_main@@YAHXZ)

I tried changing the "SubSystem" option to Windows and Console so forth, but that only resulted in the same error with a different "unresolved external symbol WinMain" message. After some research I listened the advice of someone to change the main to wmain and voila - the app was working as intended.

What makes me curious is that I didn't change any default settings from Visual Studio except for the C++ standard (which I changed from C++11 to C++17), and my other projects that do have "Use Unicode Character Set" option turned on do work with a normal main() function. So what exactly forces me to use wmain instead of the usual main here?

emredesu
  • 179
  • 1
  • 5
  • 11
  • According to [this page of the official Microsoft documentation](https://learn.microsoft.com/en-us/cpp/build/reference/subsystem-specify-subsystem?view=msvc-160), `main` or `wmain` are to be used for `/SUBSYSTEM CONSOLE` and `WinMain` or `wWinMain` are to be used for `/SUBSYSTEM WINDOWS`. – Andreas Wenzel Oct 31 '20 at 21:45
  • 1
    I find the question a little confusing, but `wmain` is the entry point for Unicode console apps. – Paul Sanders Oct 31 '20 at 22:59
  • Please post the code and build settings. SDL has its ways about main (SDL_main, SDL_MAIN_HANDLED, SDL_SetMainReady etc) and it's hard to guess which one you use. – dxiv Oct 31 '20 at 23:38

1 Answers1

2

The problem was caused by the SDL macro that extends "main" to "SDL_main". The solution was to either use

#undef main

or use the official SDL way of undefining main. Using "wmain" seemed like it solved the problem not because of unicode dependency, but because SDL does not have a macro for "wmain".

emredesu
  • 179
  • 1
  • 5
  • 11