title: Makefile: rule to put .o in different directory
body: <p>I've got this directory structure:</p>
  
  <ul>
  <li><code>./src</code> contains the the .<code>cpp</code> and the <code>.h</code> of all the files I need</li>
  <li><code>./bin</code> should contain the <code>.o</code> temporarily and the <code>.bin</code> permanently. Also, this folder should be deleted when calling <code>make clean</code>.</li>
  <li><code>./</code> contains the <code>Makefile</code></li>
  </ul>
  
  <p>This is my current <code>Makefile</code>:</p>
  
  <pre><code>CFLAGS = -Wall -pedantic -g
  CC = g++
  EXEC = flrfile
  SRC_DIR = src
  BIN_DIR = bin
  OBJ = FixedLengthFieldsRecord.o FixedLengthRecordFile.o main.o
  
  all: flrfile
  
  ../$(BIN_DIR)/%.o: $(SRC_DIR)%.cpp $(SRC_DIR)%.h
      $(CC) $(CFLAGS) -c $(SRC_DIR)%.cpp -o $@
  
  $(EXEC): $(OBJ)
      @mkdir -p bin
      $(CC) $(CFLAGS) $(BIN_DIR)/$(OBJ) -o $(BIN_DIR)/$(EXEC)
  
  .PHONY : clean
  
  clean:
      -rm -rf $(BIN_DIR)
  </code></pre>
  
  <p>When I run <code>make</code>, I get this error:</p>
  
  <pre><code>make: *** No rule to make target `FixedLengthFieldsRecord.o', needed by `flrfile'.  Stop.
  </code></pre>
  
  <p>Why is this?</p>
  
  <p>PS: Also, how could I make the <code>OBJ = FixedLengthFieldsRecord.o FixedLengthRecordFile.o main.o</code> more generic? I don't want to write all the <code>.o</code>...</p>