Add SDL to my path

血红的双手。 提交于 2019-12-08 02:43:49

问题


I install SDL via brew on my mac but I can't include it! Here is my too easy code:

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

when I compile it with cc, CC could not find SDL.h I found that brew install SDL in Cellar but cc did not check this folder Could you help me?


回答1:


I know this post has 9 months old but if someone, somewhere in the internet try to find out how to use SDL with mac, just follow this.

DL .dmg file on the SDL website (V2).

Put SDL2.framework in /Library/Frameworks

In your code :

#include <SDL.h>

and compile with those flags :

`sdl-config --cflags --libs`

Ex :

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

Use this simple code to see it working :

#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;
}


来源:https://stackoverflow.com/questions/18425812/add-sdl-to-my-path

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!