gcc无法识别某些SDL函数

时间:2019-04-05 19:32:45

标签: c linux sdl sdl-2

我正在学习使用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

2 个答案:

答案 0 :(得分:0)

您尚未声明window变量。那应该解决您所有的问题。

答案 1 :(得分:0)

谢谢大家的回答。终于genpfault是正确的,我通过apt重新安装了libsdl2-dev并替换了

#include <SDL/SDL.h> 

通过

#include <SDL2/SDL.h> 

并使用gcc disco.c ``sdl2-config --cflags --libs`` -o disco

进行编译

我还声明了窗口变量:D(Jordan Motta)