我正在尝试在使用GCC编译的C语言中使用SDL2但事件不起作用,例如,我无法使用SDL_QUIT关闭窗口。 请问代码有什么问题吗?
#include <stdlib.h>
#include <stdio.h>
#include <SDL2/SDL.h>
int main(int argc, char** argv)
{
if (SDL_Init(SDL_INIT_VIDEO) != 0) {
fprintf(stdout,"Échec\n", SDL_GetError());
return -1;
}
SDL_Window* windowImg = NULL;
SDL_Renderer* renderImg = NULL;
int quit = 0;
SDL_Event e;
windowImg = SDL_CreateWindow("Test", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 400, 400, SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE);
renderImg = SDL_CreateRenderer(windowImg, -1, SDL_RENDERER_ACCELERATED);
while (!quit) {
while (SDL_PollEvent(&e) != 0) {
if (e.type == SDL_QUIT) {
quit = 1;
break;
}
}
}
SDL_DestroyWindow(windowImg);
SDL_Quit();
return 0;
}
答案 0 :(得分:0)
好的,我忘了在构建选项中链接库&gt;链接器选项: -lSDL2main -lSDL2