title: -pthread, -lpthread and minimal dynamic linktime dependencies
body: <p>This <a href="https://stackoverflow.com/questions/23250863/difference-between-pthread-and-lpthread-while-compiling">answer</a> suggest <code>-pthread</code> is preferable to <code>-lpthread</code> because predefined macros.</p>
  
  <p>Empirically, <code>-pthread</code> gives me only one extra macro: <code>#define _REENTRANT 1</code>
  and it also appears to force <code>libpthread.so.0</code> as a dynamic linktime dependency.</p>
  
  <p>When I compile with <code>-lpthread</code>, that dependency is only added if I actually call any of the <code>pthread</code> functions.</p>
  
  <p>This is preferably to me, because then I wouldn't have to treat multithreaded programs differently in my build scripts.</p>
  
  <p>So my question is, what else is there to <code>-pthread</code> vs <code>-lpthread</code> and is it possible to use use <code>-pthread</code> without forcing said dynamic linktime dependency?</p>
  
  <p>Demonstration:</p>
  
  <pre><code>$ echo 'int main(){ return 0; }' | c gcc -include pthread.h -x c - -lpthread &amp;&amp; ldd a.out | grep pthread
  $ echo 'int main(){  return pthread_self(); }' | c gcc -include pthread.h -x c - -lpthread &amp;&amp; ldd a.out | grep pthread
  libpthread.so.0 =&gt; /lib/x86_64-linux-gnu/libpthread.so.0 (0x0000003000c00000)
  $ echo 'int main(){ return 0; }' | c gcc -include pthread.h -x c - -pthread &amp;&amp; ldd a.out | grep pthread
  libpthread.so.0 =&gt; /lib/x86_64-linux-gnu/libpthread.so.0 (0x0000003000c00000) 
  </code></pre>