title: makefile : How to link object files from different subdirectory and include different search paths
body: <p>I want to change the location of my test code (<code>tsnnls_test_DKU.c</code>) and I am unable to make change in makefile to reflect this folder change properly. Some help would be appreciated.</p>
  
  <p><strong>I have two questions:</strong>
  1) How to link object files from different subdirectory 
  2) include different search paths (3 search paths in my example).</p>
  
  <p>In my orinal setup, where makefile works fine, I put my test code <code>tsnnls_test_DKU.c</code> at following location (inside the third party libraries):</p>
  
  <pre><code>Dir1 = /home/dkumar/libtsnnls-2.3.3/tsnnls
  </code></pre>
  
  <p>All object files, that I am linking to, are at</p>
  
  <pre><code>OBJDir = /home/dkumar/libtsnnls-2.3.3/tsnnls
  </code></pre>
  
  <p>Also, some include file contained in <code>tsnnls_test_DKU.c</code> are at following three locations (<strong>three search paths</strong>):</p>
  
  <pre><code>Dir1 = /home/dkumar/libtsnnls-2.3.3/tsnnls  
  Dir2 = /home/dkumar/libtsnnls-2.3.3
  Dir3 = /home/dkumar/libtsnnls-2.3.3/tsnnls/taucs_basic
  </code></pre>
  
  <p>and my makefile works fine.</p>
  
  <p>However, I would like to change the location of test code to:</p>
  
  <pre><code>Dir4 = /home/dkumar/CPP_ExampleCodes_DKU/Using_tsnnls_DKU/
  </code></pre>
  
  <p>Here is how my makefile looks like (Updated after inputs from other user:</p>
  
  <pre><code># A sample Makefile
  
  VPATH = -L/home/dkumar/libtsnnls-2.3.3/tsnnls
  INC_PATH  = -I/home/dkumar/libtsnnls-2.3.3/ -I/home/dkumar/libtsnnls-2.3.3/tsnnls/  -I/home/dkumar/libtsnnls-2.3.3/tsnnls/taucs_basic/
  
  # Here is a simple Make Macro.
  LINK_TARGET     = tsnnls_test_DKU
  OBJS_LOC    = tsnnls_test_DKU.o
  
  # Here is a Make Macro that uses the backslash to extend to multiple lines.
  OBJS =  libtsnnls_la-taucs_malloc.o libtsnnls_la-taucs_ccs_order.o \
      libtsnnls_la-taucs_ccs_ops.o libtsnnls_la-taucs_vec_base.o \
      libtsnnls_la-taucs_complex.o libtsnnls_la-colamd.o \
      libtsnnls_la-amdbar.o libtsnnls_la-amdexa.o \
      libtsnnls_la-amdtru.o libtsnnls_la-genmmd.o \
      libtsnnls_la-taucs_timer.o libtsnnls_la-taucs_sn_llt.o \
      libtsnnls_la-taucs_ccs_base.o libtsnnls_la-tlsqr.o \
      libtsnnls_la-tsnnls.o libtsnnls_la-lsqr.o   \
      $(OBJS_LOC)
  
  REBUILDABLES = $(LINK_TARGET) 
  
  all : $(LINK_TARGET)
      echo All done
  
  clean : 
      rm -f $(REBUILDABLES)   
      echo Clean done
  
  #Inclusion of all libraries
  RANLIB = ranlib
  STATICLIB= /usr/local/lib/taucs_full/lib/linux/libtaucs.a 
  
  tsnnls_test_LDADD = $(LDADD)
  LIBS = -largtable2 -llapack -lblas -lquadmath -lm
  
  $(LINK_TARGET) : $(OBJS)   $(tsnnls_test_LDADD) $(LIBS)  $(STATICLIB)
  gcc -g ${INC_PATH} -o $@ $^
  </code></pre>
  
  <p>The error that I get when trying to run "$make"</p>
  
  <pre><code>make: *** No rule to make target `libtsnnls_la-taucs_malloc.o', needed by `tsnnls_test_DKU'.  Stop.
  </code></pre>
  
  <p>Obviously, I have not been able to use VPATH properly.</p>
  
  <p><strong>UPDATE:</strong>
  Thanks to Mike Kinghan for answering my question.</p>