To the best of my knowledge, this isn't a duplicate of an existing question. This question is specifically about Visual Studio's auto-linking SDL2 libraries.
I've installed SDL2 (x64-windows
variant) with vcpkg:
vcpkg install sdl2 --triplet x64-windows
And I've made vpkg libraries available to Visual Studio:
vcpkg integrate install
My VS 2019 project is configured to use the Console
subsystem, and my main program looks like that:
#define SDL_MAIN_HANDLED
#include <SDL2/SDL.h>
int main(int, char*[])
{
}
Why do I need to specify SDL_MAIN_HANDLED
? It seems that auto-linking with SDLmain2.lib
doesn't happen for some reason?
If I don't specify SDL_MAIN_HANDLED
, linking fails:
unresolved external symbol main referenced in function "int __cdecl invoke_main(void)" (?invoke_main@@YAHXZ)
I've also tried adding extern "C"
on main()
declaration but to no avail.
I've written many apps with SDL2 but this is the first time I'm using vcpkg to locate it.
SDL_MAIN_HANDLED
does and what it's for; what I can't figure out is why I need to use it in that specific context, and whether there's a better way to do things. – Lorenzen