英文:
Re - LINK : fatal error LNK1561: entry point must be defined while compiling SDL2 project with VS2022 Buildtools
问题
//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;
}
英文:
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:
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?
答案1
得分: 0
在 SDL.h
头文件中,main
被定义为 SDL_main
。因此,链接器找不到应用程序的入口点。只需要在 main()
函数之前写上 #undef main
即可。
英文:
In the SDL.h
header, main
is defined as SDL_main
. Therefore, the linker can't find an entry point for your application. You just need to write #undef main
before your main()
function and it should work.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论