title: Compiling SDL on OS X with makefile
body: <p>I'm trying to compile the tetris program I wrote with C++ and SDL on OS X. First I tried doing this:</p>
  
  <pre><code>`g++ -o tetris main.cpp `sdl-config --cflags --libs` -framework Cocoa`
  </code></pre>
  
  <p>and got this:</p>
  
  <pre><code>Undefined symbols:
    "Game::startGame()", referenced from:
        _main in ccQMhbGx.o
    "Game::Game()", referenced from:
        _main in ccQMhbGx.o
  ld: symbol(s) not found
  collect2: ld returned 1 exit status
  </code></pre>
  
  <p>Here is the main.cpp file:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include "Game.h"
  
  int main(int argc, char* argv[]) {
   Game *game = new Game();
   game-&gt;startGame();
  
   return 0;
  }
  </code></pre>
  
  <p><code>Game.h</code> is the game class where all of the other classes (Board.h, IO.h, Piece.h, Pieces.h) are included and the main logic of the game is contained.</p>
  
  <p>I'd really like to be able to write a makefile for this or find some way to easily distribute it to friends.</p>
  
  <p>EDIT:</p>
  
  <p>here is the final makefile in case anyone else is having the same problem:</p>
  
  <pre><code>CC=g++
  CFLAGS=-c -Wall
  SDLFLAGS=`sdl-config --cflags --libs` -framework Cocoa
  SOURCES=main.cpp Game.cpp IO.cpp Board.cpp Pieces.cpp Piece.cpp
  OBJECTS=$(SOURCES:.cpp=.o)
  EXECUTABLE=tetris
  
  all: $(SOURCES) $(EXECUTABLE)
  
  $(EXECUTABLE): $(OBJECTS)
   $(CC) $(OBJECTS) $(SDLFLAGS) -o $@
  
  .cpp.o:
   $(CC) $(CFLAGS) $&lt; -o $@
  
  clean:
   rm -rf *.o $(EXECUTABLE)
  </code></pre>