title: Makefile and linking .a libraries
body: <p>I've got a <code>src</code> folder which, after running <code>make</code>, creates 4 libraries in <code>.a</code> format.
  There's also a folder <code>tests</code> which contains <code>tests.cpp</code>. This file depends on the libraries previously mentioned.</p>
  
  <p>I'm trying to get a Makefile inside <code>tests</code> that generates the libraries inside <code>src</code> (this it does) and then uses these to compile <code>tests.cpp</code> (this it doesn't - I get many many undefined references, as if it weren't linking properly).</p>
  
  <p>The folder <code>tests</code> contains this <code>Makefile</code>:</p>
  
  <pre><code>include ../src/makefile.inc
  
  DIR = ../src
  OBJLIBS = ../src/CapaFisica.a ../src/CapaLogica.a ../src/CapaInterfaz.a ../src/Utilitarios.a
  
  TARGETS = tests.cpp
  EXE = tests
  
  all : $(EXE)
  
  %.a :
      -for d in $(DIR); do (cd $$d; $(MAKE)); done
  
  tests:  $(OBJLIBS)
      $(CC) $(CFLAGS) $(OBJLIBS) -o $@ $(TARGETS)
  
  clean :
      $(ECHO) Borrando archivos.
      -$(RM) -f ./tests
      cd $(DIR); make clean
      find . -name "*.o" -type f -print | xargs /bin/rm -f
  </code></pre>
  
  <p>What am I doing wrong?</p>