我开始使用 SDL 和 C 编程。我有其他编程语言的经验,但是在 C 中链接/编译库对我来说是新的。我使用的是 Mac 10.8,并按照自述文件 ( ./configure; make; make install
) 中的说明安装了最新的稳定版 2.0。这是我要编译的示例代码:
#include <stdlib.h>
#include <stdio.h>
#include "SDL.h"
int main(void)
{
if (SDL_Init(SDL_INIT_VIDEO|SDL_INIT_TIMER) != 0) {
fprintf(stderr, "\nUnable to initialize SDL: %s\n", SDL_GetError());
return 1;
}
atexit(SDL_Quit);
return 0;
}
当我尝试使用 编译脚本gcc example.c
时,出现错误:
example.c:3:17: error: SDL.h: No such file or directory
example.c: In function ‘main’:
example.c:7: error: ‘SDL_INIT_VIDEO’ undeclared (first use in this function)
example.c:7: error: (Each undeclared identifier is reported only once
example.c:7: error: for each function it appears in.)
example.c:7: error: ‘SDL_INIT_TIMER’ undeclared (first use in this function)
example.c:8: warning: format ‘%s’ expects type ‘char *’, but argument 3 has type ‘int’
example.c:8: warning: format ‘%s’ expects type ‘char *’, but argument 3 has type ‘int’
example.c:11: error: ‘SDL_Quit’ undeclared (first use in this function)
我尝试搜索 wiki、教程以及我能找到的任何类型的文档,但我在任何地方都找不到任何示例来说明如何正确编译使用 SDL 的 C 程序。
我需要做什么来编译这个程序?