我正在学习使用SDL,不幸的是我不明白为什么linux上的gcc会误解我的代码并用其他函数解释它并给我这些编译错误。我看不出那可能来自哪里。
disco.c:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <SDL/SDL.h>
void SDLdebugError();
int main(int argc, char const *argv[]) {
SDL_Init(SDL_INIT_VIDEO);
SDL_Window SDL_CreateWindow("Chicken Disco", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 800, 600, SET_WINDOW_OPENGL);
if(window == NULL) { SDLdebugError("Window Error"); };
SDL_Quit();
return EXIT_SUCCESS;
}
void SDLdebugError(char *message) {
printf("%s, %s\n", message, SDL_GetError());
exit(EXIT_FAILURE);
}
汇编:
disco.c: In function ‘main’:
disco.c:12:3: error: unknown type name ‘SDL_Window’; did you mean ‘SDL_cond’?
SDL_Window SDL_CreateWindow("Chicken Disco", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 800, 600, SET_WINDOW_OPENGL);
^~~~~~~~~~
SDL_cond
disco.c:12:31: error: expected declaration specifiers or ‘...’ before string constant
SDL_Window SDL_CreateWindow("Chicken Disco", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 800, 600, SET_WINDOW_OPENGL);
^~~~~~~~~~~~~~~
disco.c:12:48: error: unknown type name ‘SDL_WINDOWPOS_CENTERED’; did you mean ‘SDL_HAT_CENTERED’?
SDL_Window SDL_CreateWindow("Chicken Disco", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 800, 600, SET_WINDOW_OPENGL);
^~~~~~~~~~~~~~~~~~~~~~
SDL_HAT_CENTERED
disco.c:12:72: error: unknown type name ‘SDL_WINDOWPOS_CENTERED’; did you mean ‘SDL_HAT_CENTERED’?
DL_Window SDL_CreateWindow("Chicken Disco", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 800, 600, SET_WINDOW_OPENGL);
^~~~~~~~~~~~~~~~~~~~~~
SDL_HAT_CENTERED
disco.c:12:96: error: expected declaration specifiers or ‘...’ before numeric constant
ow("Chicken Disco", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 800, 600, SET_WINDOW_OPENGL);
^~~
disco.c:12:101: error: expected declaration specifiers or ‘...’ before numeric constant
hicken Disco", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 800, 600, SET_WINDOW_OPENGL);
^~~
disco.c:12:106: error: unknown type name ‘SET_WINDOW_OPENGL’; did you mean ‘SDL_VIDEO_OPENGL’?
n Disco", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 800, 600, SET_WINDOW_OPENGL);
^~~~~~~~~~~~~~~~~
SDL_VIDEO_OPENGL
disco.c:13:6: error: ‘window’ undeclared (first use in this function); did you mean ‘rindex’?
if(window == NULL) { SDLdebugError("Window Error"); };
^~~~~~
rindex
您尚未声明window
变量。这应该解决你所有的问题。
谢谢大家的答案。最后genpfault是对的,我通过apt重新安装了libsdl2-dev并更换了
#include <SDL/SDL.h>
通过
#include <SDL2/SDL.h>
并编译:gcc disco.c ``sdl2-config --cflags --libs`` -o disco
我还声明了窗口变量:D(Jordan Motta)