【问题标题】:Add SDL to my path将 SDL 添加到我的路径
【发布时间】:2013-08-27 20:40:49
【问题描述】:

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

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

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

【问题讨论】:

  • 对mac不熟悉,可以试试#include &lt;SDL/SDL.h&gt;吗?在 Linux 上为我工作。
  • 我想安装包,那个包抛出这个错误,所以我不能编辑它!

标签: sdl homebrew cc


【解决方案1】:

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

【讨论】:

  • 当我下载它并将其放入 /Library/Frameworks 时,它起作用了。但它找不到 sdl-config 程序。
  • Nvm,我安装了sdl2,所以需要sdl2-config
  • 安装框架后,我没有找到 sdl-config 和 sdl2-config。这些命令应该在哪里?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-11-17
  • 2021-02-25
  • 1970-01-01
  • 2022-06-15
  • 2014-04-18
  • 2017-08-11
相关资源
最近更新 更多