title: Makefile Fatal error: can't create obj/calc.o
body: <p>I'm trying to make a makefile for a simple calculator for a college project. I need it done, and I've searched the web for tutorials and I eventually found this code: </p>
  
  <pre><code>IDIR =include
  CC=gcc
  CFLAGS=-I$(IDIR)
  
  ODIR=obj
  LDIR=lib
  SDIR=src
  
  LIBS=-lm
  
  _DEPS = calc.h
  DEPS = $(patsubst %,$(IDIR)/%,$(_DEPS))
  
  _OBJ = calc.o libcalc.o 
  OBJ = $(patsubst %,$(ODIR)/%,$(_OBJ))
  
  
  $(ODIR)/%.o: $(SDIR)/%.c $(DEPS)
      $(CC) -c -o $@ $&lt; $(CFLAGS)
  
  calc: $(OBJ)
      gcc -o $@ $^ $(CFLAGS) $(LIBS)
  
  .PHONY: clean
  
  clean:
      rm -f $(ODIR)/*.o *~ core $(INCDIR)/*~ 
  </code></pre>
  
  <p>The output of the make command is</p>
  
  <pre><code>gcc -c -o obj/calc.o calc.c -I../include
  Assembler messages:
  Fatal error: can't create obj/calc.o: No such file or directory
  make: *** [obj/calc.o] Error 1
  </code></pre>
  
  <p>My professor gave us no lead nor instruction to this, so I'm really lost.</p>
  
  <p>My project is divided in three folders: <code>lib</code>, <code>src</code> and <code>include</code>. <code>src</code> contains the source for the project, named <code>calc.c</code>, <code>include</code> contains the header named <code>calc.h</code>, and <code>lib</code> contains the library named <code>libcalc.c</code>.</p>
  
  <p>EDIT: I figured out this error, and it was that the <code>obj</code> directory under <code>src</code> wasn't created. However, it's still not working. The new error message is: </p>
  
  <pre><code>make: *** No rule to make target `obj/libcalc.o', needed by `calc'.  Stop.
  </code></pre>
  
  <p>EDIT 2: I just moved the libcalc.c from lib to obj and it worked fine. Not ideal, but it does what I need.</p>