title: Optimization and flags for making a static library with g++
body: <p>I am just starting with g++ compiler on Linux and got some questions on the compiler flags. Here are they</p>
  
  <p><strong>Optimizations</strong></p>
  
  <p>I read about optimization flags <code>-O1</code>, <code>-O2</code> and <code>-O3</code> in the g++ manual page. I didn't understood when to use these flags. Usually what optimization level do you use? The g++ manual says the following for <code>-O2</code>.</p>
  
  <blockquote>
    <p>Optimize even more. GCC performs nearly all supported optimizations that do not involve a space-speed tradeoff. The compiler does not perform loop unrolling or function inlining when you specify -O2. As compared to -O, this option increases both compilation time and the performance of the generated code. </p>
  </blockquote>
  
  <p>If it is not doing inlining and loop unrolling, how the said performance befits are achieved and is this option recommended?</p>
  
  <p><strong>Static Library</strong></p>
  
  <p>How do I create a static library using g++? In Visual Studio, I can choose a class library project and it will be compiled into "lib" file. What is the equivalent in g++?</p>