-2

I am using SDL2 and vcpkg. I install sdl2 by vcpkg and build project in Visual Studio 2022 Debug x86

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

code:

#include "SDL2/SDL.h"

const int WINDOW_WIDTH = 640;
const int WINDOW_HEIGHT = 480;

int main(int argc, char* argv[]) {
    SDL_Window* window = NULL;
    SDL_Surface* surface = NULL;
    if (SDL_Init(SDL_INIT_VIDEO) < 0) {
        printf("%s\n", SDL_GetError());

    }
    return 0;
}
Neoxy
  • 1
  • 1
  • There doesn't seem to be anything wrong with the code, the `main` function is clearly there. So it seems that there is something wrong with the way you are building your code, or the way you have set up your project. So you should say a little more about that, – john Aug 21 '22 at 06:53
  • Okay I install sdl2 by vcpkg and build project in Visual Studio 2022 Debug x86 – Neoxy Aug 21 '22 at 07:58
  • 1
    SDL tries hard to stop you from creating a console-mode program. Using the correct project template to get started is very important, any half-decent tutorial should point this out. – Hans Passant Aug 21 '22 at 09:03

1 Answers1

3

(More of a comment than a solution, but I cannot comment yet)

Have you tried the solutions proposed in this thread?

According to an answer there, the most probable solution would be that your Linker's SubSystem setting is not set to Windows: SubSettingsExample

Apart from that, there are some other potential solutions in that thread, if none of them work, please report back.