Mac OS X (10.8), SDL & Homebrew: Undefined symbols

On OS X, running:

brew install sdl

Won’t link and

sudo brew link sdl

Won’t link either (not supposed to run brew as root either).

When you compile something for SDL (even the most trivial SDL program), it’ll report:

Undefined symbols for architecture x86_64:

  “_SDL_GetError”, referenced from:

      _SDL_main in ccKV9YwC.o

  “_SDL_GetKeyName”, referenced from:

      _DisplayKey in ccKV9YwC.o

  “_SDL_Init”, referenced from:

      _SDL_main in ccKV9YwC.o

  “_SDL_PollEvent”, referenced from:

      _SDL_main in ccKV9YwC.o

  “_SDL_Quit”, referenced from:

      _SDL_main in ccKV9YwC.o

  “_SDL_SetVideoMode”, referenced from:

      _SDL_main in ccKV9YwC.o

  “_main”, referenced from:

      start in crt1.10.6.o

     (maybe you meant: _SDL_main)

ld: symbol(s) not found for architecture x86_64

collect2: ld returned 1 exit status

To fix that, do the following:

sudo ln -s /usr/local/Cellar/sdl/1.2.15/include/SDL /usr/local/include/

sudo ln -s /usr/local/Cellar/sdl/1.2.15/ /usr/local/opt/sdl 

After this, SDL software compiles like this:

gcc -L/usr/local/opt/sdl/lib -lSDLmain -lSDL -framework Cocoa SDL_Keyboard.c

Be the first to leave a comment. Don’t be shy.

Join the Discussion

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>