title: Why the size of exe file is more, when we use a static library than the shared library
body: <p>I got some question regarding the shared and static libraries.So let me tell you what i did is, I have created a static library and also a shared library using the gcc commands and the size of libarith.a is 6KB and size of libarith.so is 18KB.Both the libraries contain the same functions.</p>
  
  <p>I used one simple function(say add(a,b)) in my make.c file and linked the static library using these gcc command,</p>
  
  <pre><code>           gcc -L/cygdrive/c/cpros make.c -larith.a # used a static library
  </code></pre>
  
  <p>the size of the exe file is 16.1 KB.</p>
  
  <p>Next I used the same function(same add(a,b)) in my make.c file but these time using shared library, like these.</p>
  
  <pre><code>          gcc make.c /cygdrive/c/cpros/libarith.so #used a shared library
  </code></pre>
  
  <p>unfortunately the size of exe file is 12.1 KB. I wonder how? becuase  the size of libarith.so is 18 KB when compared to libarith.a which is just 6 KB.But at the end the exe file generated using the shared library is less compared to static library.</p>
  
  <p>Can anyone give me a good reason for that ? If shared libraries consume less memory then why dont we go for shared libraries all the time.Please let me know when do we use shared libraries and when do use static libraries.</p>
  
  <p>Yes when I was creating a shared library using -fPIC it gave me a warning position independent code. What does that warning actually mean?</p>