sdl - 将 SDL 添加到我的路径

标签 sdl homebrew cc

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

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

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

最佳答案

我知道这篇文章已有 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;
}

关于sdl - 将 SDL 添加到我的路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18425812/

相关文章:

无法在 Ubuntu 上运行 SDL(2),没有可用的视频设备

c++ - 2D 平台碰撞处理

audio - Mix_Chunk 和 Mix_Music 有什么区别?

mongodb - 套接字异常 : Address already in use MONGODB

c++ - 有没有办法在 ".O"文件中创建一个没有 main() 函数的 ".C"文件

c++ - SDL_opengl_glext.h 的用途是什么?

git - Brew 找不到 git,即使路径中有 git (Mac/OSX)

postgresql - 无法安装 postgres(因为 readline)

c - C代码错误: expression is not assignable错误

C++0x 编译器支持问题