title: Why do I need to include .o files when compiling?
body: <p>When I compiled my program and ran it, I got a a symbol lookup error. I was doing this:</p>
  
  <pre><code>$ gcc -o parts parts.c -lnettle
  $ ./parts
  $ ./parts: symbol lookup error: ./parts: undefined symbol: nettle_pbkdf2
  </code></pre>
  
  <p>My code included these header files:</p>
  
  <pre><code>#include &lt;nettle/pbkdf2.h&gt;
  #include &lt;nettle/hmac.h&gt;
  #include &lt;pbkdf2-hmac-sha1.c&gt;
  </code></pre>
  
  <p>I solved my problem by including the object files for the two included header files during gcc compilation.</p>
  
  <pre><code>$ gcc -o parts parts.c hmac.o pbkdf2.o -lnettle
  </code></pre>
  
  <p>The thing is, I don't understand what is going on and therefore why this works. Why must I include the .o files and not just the header files to avoid symbol lookup or undefined reference errors?</p>