title: Why create a .a file from .o for static linking?
body: <p>Consider this code:</p>
  
  <p>one.c:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  int one() {
     printf("one!\n");
     return 1;
  }
  </code></pre>
  
  <p>two.c:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  int two() {
     printf("two!\n");
     return 2;
  }
  </code></pre>
  
  <p>prog.c</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  int one();
  int two();
  
  int main(int argc, char *argv[]) 
  {
     one();
     two();
  
     return 0;
  }
  </code></pre>
  
  <p>I want to link these programs together. So I do this:</p>
  
  <pre><code>gcc -c -o one.o one.c
  gcc -c -o two.o two.c
  gcc -o a.out prog.c one.o two.o
  </code></pre>
  
  <p>This works just fine.</p>
  
  <p>Or I could create a static library:</p>
  
  <pre><code>ar rcs libone.a one.o
  ar rcs libtwo.a two.o
  gcc prog.c libone.a libtwo.a
  gcc -L. prog.c -lone -ltwo
  </code></pre>
  
  <p>So my question is: why would I use the second version - the one where I created a ".a" files - rather than linking my ".o" files? They both seem to be statically linking, so is there an advantage or architectural difference in one vs another?</p>