Set up SDL2 on your Mac without Xcode

Sarah Edkins
Apr 30, 2017 · 2 min read

This is a super simple guide to get SDL2 installed and linked into your project so you can get to the fun stuff (game development) quickly. Created with massive amounts of help from Deacon Blues.

1. Install SDL2

In your terminal, run the brew command:

brew install sdl2

This will fetch a compiled version of SDL2, so you don’t need to worry about any of the compilation steps mentioned in the SDL docs (

2. Create a project

mkdir myproject
cd myproject
touch main.cpp
touch Makefile
mkdir include
mkdir lib

In myproject/main.cpp:

#include <iostream>
#include <SDL2/SDL.h>
using namespace std;
int main() {
cout << "Hello World!";
return 0;

3. Move the SDL files into your project

It might help to use Finder for this part. Navigate to the place where SDL2 installed. For me, that was:


Copy the contents of


(It should be a folder called SDL2 that contains a bunch of .h files.)

and paste it into


Then, go to


and copy the contents (some folders and some .a and .dylib files) into


4. Create your Makefile to compile using SDL2

In myproject/Makefile:

g++ main.cpp -o play -I include -L lib -l SDL2-2.0.0

Note: Flags are used to link SDL2 to your project.

`-I` (i as in include) tells it additional include directories you want to add

`-L` tells it additional library directories you want to add

`-l` (lowercase l as in lib) tells it specific library binaries you want to add

5. Make your project

In your project’s directory, in the terminal, run:

make game

This will compile the game.

6. Run your project


This step runs the executable created by compiling. If all went well, you should see a nice “Hello World!” print. That means you’ve got SDL2 hooked up. Congrats!!

All set! Now what?

This tutorial is pretty awesome for actually using SDL2:

And, if you’re wondering what SDL2 even is…

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store