2013-08-25 44 views
2

我在我的Mac上通過brew安裝SDL,但無法包含它! 這裏是我太容易代碼:將SDL添加到我的路徑

#include <SDL.h> 
int main(){ 
    return 0; 
} 

,當我和CC編譯,CC找不到SDL.h 我發現,釀造酒窖中安裝SDL但CC沒有檢查該文件夾 你能幫我?

+0

不熟悉MAC,但你可以嘗試'的#include '?適用於Linux。 – olevegard

+0

我想安裝軟件包,並且該軟件包拋出此錯誤,所以我不能編輯它! – Aryan

回答

8

我知道這篇文章已經9個月了,但如果有人在互聯網上的某個地方嘗試瞭解如何使用SDL和Mac,那麼請按照下面的步驟操作。

SDL網站(V2)上的DL .dmg文件。

認沽SDL2.framework在/ Library /框架

在您的代碼:

#include <SDL.h> 

,並與標誌編譯:

`sdl-config --cflags --libs` 

例:

gcc test.c `sdl-config --cflags --libs` 

使用這個簡單的代碼,看看它的工作:

#include <stdlib.h> 
#include <stdio.h> 
#include <SDL/SDL.h> 

int main(int argc, char *argv[ ]) 
{ 
    SDL_Surface *screen; 
    if(SDL_Init(SDL_INIT_VIDEO) == -1) 
    { 
     printf("Can't init SDL: %s\n", SDL_GetError()); 
     return EXIT_FAILURE; 
    } 

    atexit(SDL_Quit); 
    screen = SDL_SetVideoMode(640, 480, 16, SDL_HWSURFACE); 

    if(screen == NULL) 
    { 
     printf("Can't set video mode: %s\n", SDL_GetError()); 
     return EXIT_FAILURE; 
    } 

    SDL_Delay(3000); 

    return EXIT_SUCCESS; 
} 
+0

當我將它下載並放入/ Library/Frameworks時,它工作正常。但它找不到sdl-config程序。 –

+1

Nvm,我安裝了sdl2,所以它需要'sdl2-config' –