title: Why do I have to explicitly link to pthreads in my main.c compilation when my main.c does not use pthreads?
body: <p>In Linux, I have a shared library I made that uses pthreads and a main.c that does not. </p>
  
  <p>libpthread.so shows up in an ldd of my shared library, which is correct.</p>
  
  <pre><code>$ ldd libmapreduce.so.1.0 
      linux-gate.so.1 =&gt;  (0x0067d000)
      libpthread.so.0 =&gt; /lib/libpthread.so.0 (0x0058c000)
      [...]
  </code></pre>
  
  <p>But when I compile and link my main.c that does not use pthreads to my shared library that does, I see:</p>
  
  <pre><code>$ icc -Wall -o main main.c -lmapreduce
      /opt/intel/Compiler/11.1/046/lib/ia32/libiomp5.so: undefined reference to `pthread_atfork'
  </code></pre>
  
  <p>Adding -lpthread to my compile command, i.e., </p>
  
  <pre><code>$ icc -Wall -o main main.c -lmapreduce -lpthread
  </code></pre>
  
  <p>resolves the undefined reference.</p>
  
  <p>Why do I need to explicitly link to libpthread when my main.c does not use it and my shared library already has libpthread linked in?</p>