title: Statically linking libraries in MinGW
body: <p>Suppose I have three C source files. The first two to be LIBs (lib*.a?), and the third is an application which uses them.</p>
  <p>The first is (re.c):</p>
  <pre><code>int re(int i) {
      return i;
  }
  </code></pre>
  <p>The second is (test.c):</p>
  <pre><code>int re(int); // Depends on re.c
  
  int test(int i) {
      return re(i);
  }
  </code></pre>
  <p>And the third is (main.c):</p>
  <pre><code>#include&lt;stdio.h&gt;
  
  int test(int); // Uses test.c
  
  int main(void) {
      
      printf(&quot;%d\n&quot;,test(0));
      return 0;
  }
  </code></pre>
  <p>Now how can I create the first two LIBs in such a way that allows me to statically link them later with main application?</p>
  <p>I know how to create the DLLs and link them dynamically in my application such as:</p>
  <blockquote>
  <p>cc -o re.dll re.c -shared -Wl,--out-implib=libre.a (for re.c)</p>
  <p>cc -o test.dll test.c -L. -lre -shared -Wl,--out-implib=libtest.a (for test.c)</p>
  <p>cc -o main.exe main.c -L. -lre -ltest</p>
  </blockquote>
  <hr />
  <p>So how to create equivalent LIBs to be statically linked within my executable binary in MinGW, and how to link them?</p>
  <p>Obviously, under Windows :)</p>