我正在開始使用SDL和C編程。我有其他編程語言的經驗,但在C中鏈接/編譯庫對我來說是新的。我使用的是Mac 10.8,並使用讀我的說明(./configure; make; make install
)安裝了最新的穩定版2.0。下面是我在試圖編譯示例代碼:如何編譯用C編寫的示例SDL程序?
#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程序。
我需要做些什麼來編譯這個程序?
這真的很有幫助,謝謝! – Andrew