我正在学习SDL和C语言编程。我有其他编程语言的经验,但在C语言中链接/编译库是新的挑战。我正在使用Mac 10.8,并按照read me中的说明安装了最新稳定版2.0(./configure; make; make install
)。这里是我正在尝试编译的示例代码:
#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)
我尝试搜索维基、教程和任何可找到的文档,但我无法找到任何示例来展示如何正确编译一个使用SDL的C程序。
我需要做什么来编译这个程序?