title: gcc -fPIC vs. -shared
body: <p>When compiling a shared library with gcc / g++, why is <code>-fPIC</code> not implied by <code>-shared</code> option? Or, said differently, is the option <code>-fPIC</code> required at link time?</p>
  
  <p>For short, should I write:</p>
  
  <pre><code>gcc -c -fPIC foo.c -o foo.o
  gcc -shared -fPIC foo.o -o libfoo.so  // with -fPIC
  </code></pre>
  
  <p>or is the following sufficient:</p>
  
  <pre><code>gcc -c -fPIC foo.c -o foo.o
  gcc -shared foo.o -o libfoo.so // without -fPIC
  </code></pre>