Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Re – LINK : fatal error LNK1561: entry point must be defined while compiling SDL2 project with VS2022 Buildtools

I am trying to compile this code –

//main.cpp

#include<SDL.h>

int main(int argc,char* argv[])
{
    if(SDL_Init(SDL_INIT_VIDEO))
    {
        return 1;
    }
        SDL_Window* window=SDL_CreateWindow("Project Igloo",(1366-640)/2,(768-480)/2,640,480,SDL_WINDOW_SHOWN);
        if(!window)
        {
            SDL_Log("Error : failed to create window: %s\n",SDL_GetError());
        }
        else
        {
            SDL_Renderer* renderer=SDL_CreateRenderer(window,-1,SDL_RENDERER_PRESENTVSYNC);
            if(!renderer)
            {
                SDL_Log("Error - failed to create renderer: %s\n",SDL_GetError());
            }
            else
            {
                SDL_Rect fillrect={(640-200)/2,(480-200)/2,200,200};
                SDL_SetRenderDrawColor(renderer,0xff,0xff,0xff,0xff);
                SDL_RenderClear(renderer);
                SDL_SetRenderDrawColor(renderer,0x80,0x80,0x80,0xff);
                SDL_RenderFillRect(renderer,&fillrect);
                SDL_RenderPresent(renderer);

                SDL_Event event;
                bool running=true;
                while(running)
                {
                    while(SDL_PollEvent(&event))
                    {
                        if(event.type==SDL_QUIT)
                        running=false;
                    }

                }

                SDL_DestroyRenderer(renderer);
            }

            SDL_DestroyWindow(window);
        }
        SDL_Quit();
    return 0;
}

However, every time I get the LINK : fatal error LNK1561: entry point must be defined error.

With Visual Studio 2022 BuildTools Edition, using the commands:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

cl /EHsc /Iinclude main.cpp SDL2main.lib SDL2.lib /link /out:main.exe

cl /EHsc /Iinclude main.cpp SDL2.lib SDL2main.lib /link /out:main.exe

cl /EHsc /Iinclude SDL2main.lib SDL2.lib main.cpp /link /out:main.exe

cl /EHsc /Iinclude SDL2.lib SDL2main.lib main.cpp /link /out:main.exe

I followed this link however the accepted answer told to use Console (/SUBSYSTEM:CONSOLE) which requires installing other VC edition. Can I even compile SDL2 program without using edition other than BuildTools one? Do I need to add some other information to command line?

Thanks

>Solution :

In the SDL.h header main is defined as SDL_main. Therefore the linker cant find an entry point for your application. You just need to write #undef main before your main() function and it should work.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading