title: How to create a static library that is statically linked against c/c++ standard libraries?
body: <p>I want to create a trivial static library <code>my_math.lib</code>. Its header and source files are given as follows.</p>
  <pre><code>// my_math.h
  #ifndef MY_MATH_H
  #define MY_MATH_H
  
  double reciprocal(double d);
  #endif
  
  // my_math.cpp
  #include &quot;my_math.h&quot;
  #include &lt;iostream&gt;
  double reciprocal(double d)
  {
      std::cout &lt;&lt; __func__ &lt;&lt; std::endl;
  
      return 1.0 / d;
  }
  </code></pre>
  <p>For the sake of learning purposes, I compile it in discreate steps as follows:</p>
  <ol>
  <li>Preprocessing: <code>cpp my_math.cpp &gt; my_math.ii</code></li>
  <li>Compiling: <code>g++ -S my_math.ii</code> (where the output is <code>my_math.s</code> by default)</li>
  <li>Assembling: <code>as my_math.s -o my_math.o</code></li>
  <li>Archiving: <code>ar rvs my_math.a my_math.o</code></li>
  </ol>
  <h1>Question</h1>
  <p>As you can see, my library above uses <code>cout</code> defined in c/c++ standard libraries.</p>
  <p>For academic purposes, is it possible to create a static library <code>my_math.lib</code> that statically links against c/c++ libraries? I did not find any articles that show how to do so.</p>
  <p>Can we extend the archiving step to also include static linking against c/c++ standard libraries? In other words, is it possible to use <code>-static</code> option provided by <code>g++</code> when creating static libraries?</p>
  <h1>Edit:</h1>
  <p>As the expected <code>my_math.lib</code> contains both my own code and c/c++ standard libraries, someone who uses <code>my_math.lib</code> will only need to have both <code>my_math.h</code> and <code>iostream</code>, and statically links against <code>my_math.lib</code>. The resulting <code>.exe</code> binary does not need c/c++ runtime anymore. This is the scenario I want to achieve for academic purposes!</p>