title: C: Creating static library and linking using a Makefile
body: <p>I am trying to <a href="http://randu.org/tutorials/c/libraries.php" rel="noreferrer">understand static and shared Libraries</a>.</p>
  
  <p>I want to do the following to create a makefile that does separate compilation and linking such that a static library is created and linked
  in forming the final static executable.</p>
  
  <p>I have the following code for the Makefile, but I am getting the following error</p>
  
  <p><code>Makefile:13: *** missing separator.  Stop.</code></p>
  
  <p>But I am also trying to understand how to actually link/create libraries.</p>
  
  <p>If I run the commands after <code>line 12</code> in the terminal they work, but not in the makefile.</p>
  
  <pre><code>myProgram: main.o addSorted.o freeLinks.o
      gcc -lm -o myProgram main.o addSorted.o freeLinks.o
  
  main.o: main.c
      gcc -O -c -lm main.c main.h
  
  addSorted.o: addSorted.c addSorted.h
      gcc -O -c -lm addSorted.c
  
  freeLinks.o: freeLinks.c freeLinks.h
      gcc -O -c -lm freeLinks.c
  
  ar rc libmylib.a main.o addSorted.o freeLinks.o    //Error Line
  
  ranlib libmylib.a
  
  gcc -o foo -L. -lmylib foo.o
  
  clean:
      rm -f myProgram main.o addSorted.o freeLinks.o
  </code></pre>
  
  <p>Also, if you can assist in improving the code, I would really appreciate it.</p>