2

我在我的 Mac 上通过 brew 安装 SDL,但我无法包含它!这是我太简单的代码:

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

当我用 cc 编译它时,CC 找不到 SDL.h 我发现 brew install SDL in Cellar 但 cc 没有检查这个文件夹你能帮我吗?

4

1 回答 1

8

我知道这篇文章已有 9 个月的历史,但如果有人在互联网上的某个地方尝试了解如何在 mac 中使用 SDL,请按照此操作。

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

将 SDL2.framework 放入 /Library/Frameworks

在您的代码中:

#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;
}
于 2014-06-09T17:44:36.007 回答