问题
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