I have installed SDL2 using Homebrew but now I don\'t know how to make sure Xcode can use it! I imported the created library and added it to the build phases tab of my proje
brew search sdl2
brew install sdl2 sdl2_image sdl2_mixer sdl2_net sdl2_ttf
config xcode Build Settings --> All --> Search Paths --> Header Serch Paths
--> /usr/local/include
config Xcode General ->add Frameworks and Libraries --> libSDL2-2.0.0.dylib
test your code
#include <iostream>
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
using namespace std;
int main() {
if(SDL_Init(SDL_INIT_VIDEO) < 0) {
cout << "SDL init failed." << endl;
return 1;
}
cout << "SDL Init succeeded." << endl;
SDL_Quit();
return 0;
}
To be able to use SDL2 on Xcode you must set two things (which are required for SDL in general):
-Iheader/path
).framework
)To know the correct paths you should invoke sdl2-config --cflags
and sdl2-config --libs
. On my system these produce:
:~jack$ /usr/local/bin/sdl2-config --cflags
-I/usr/local/include/SDL2 -I/usr/X11R6/include -D_THREAD_SAFE
:~jack$ /usr/local/bin/sdl2-config --libs
-L/usr/local/lib -lSDL2
Now just paste the first one into other C flags
and the other one into other linker flags
field of your project and you are ready to go.
You could set them up in the correct fields, which is Header Search Paths
for -I
and Library Search Path
for -l
but the result will be the same.