How to static link SDL2?

I’m on mac OS and I try to static or dynamic (with executable relative path) link SDL2 to my program (with image and ttf) but all my attempts don’t work.

Someone would be how I should go about it? Is it OS specific ?

Here is my Makefile :

all : prog
prog : main.o Game.o 
	gcc main.o Game.o -static -lSDL2 -lSDL2_image -lSDL2_ttf -o prog
<Makefile suite>

For dynamic linking, you’ll want to use something like

    cc -o prog main.o Game.o `sdl2-config --cflags --libs` `pkg-config sdl2_image --cflags --libs` `pkg-config sdl2_ttf --cflags --libs`

and it should work (assuming you have SDL2, SDL2_image, and SDL2_ttf installed via Homebrew or somesuch).

This is still only dynamic linking, though. Your users will have to install those libraries. For a static build, you’ll have to build your own static libs for SDL2, SDL2_image, and SDL2_ttf, copy them to your source directory, and then use them like this (if memory serves):

    cc -o prog main.o Game.o SDL2.a SDL2_image.a SDL2_ttf.a `sdl2-config --cflags` `pkg-config sdl2_image --cflags` `pkg-config sdl2_ttf --cflags`

but then you’re stuck building your own static versions (Homebrew only installs the dynamic versions, as far as I can tell).

If this is for something you’re planning on distributing, a better solution would be to build a full MacOS app (instead of a raw binary) and include whatever frameworks and libraries you need in the app bundle. The latest Xcode will even automatically add a build step to copy them to your app bundle for you once you tell it to link to them. IIRC, you can do Xcode builds from the command line with xc-run