title: C: Correct Way to Statically / Dynamically Link with MinGW-w64
body: <p><strong>Intuitively:</strong></p>
  
  <ul>
  <li>MinGW-w64 is a Windows port of the GNU compiler tools (GCC, etc.).</li>
  <li>Pre-compiled binaries for Windows are <code>.dll</code> (dynamic linking) / <code>.lib</code> (static linking).</li>
  <li>However, MinGW-w64 uses the GNU compiler tools, it would follow that <code>.so</code> / <code>.a</code> binaries are required.</li>
  </ul>
  
  <p><strong>What I've Found:</strong></p>
  
  <ul>
  <li>According to <a href="https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/4/html/Using_ld_the_GNU_Linker/win32.html" rel="noreferrer">Red Hat Enterprise Linux documentation</a>, seems that MinGW/MinGW-w64/Cygwin linkers look for <a href="https://stackoverflow.com/q/15852677/5209610"><code>.dll</code>s and <code>.a</code>s</a></li>
  <li>According to <a href="https://www.codeproject.com/articles/84461/mingw-static-and-dynamic-libraries" rel="noreferrer">this tutorial</a>, you should dynamically link to <code>.so</code> and statically link to <code>.a</code>.</li>
  <li>One question on SO indicates you can <a href="https://stackoverflow.com/a/34902737/5209610">statically link a <code>.lib</code></a> and another on SO <a href="https://stackoverflow.com/q/12155751/5209610">says it doesn't work</a>. </li>
  </ul>
  
  <p>Unfortunately, I can't find explicit documentation from MinGW &amp; MinGW-w64 that says what's right and what's wrong when dynamically/statically linking libraries.</p>
  
  <p>In my experience, I have always been able to dynamically link to <code>.dll</code>s. Once, I was able to statically link to a <code>.lib</code> (using the <code>-static</code> flag).</p>
  
  <p><strong>Question:</strong> </p>
  
  <p>Are <code>.dll</code> / <code>.a</code> binaries appropriate to dynamically and statically link libraries when compiling with the MinGW-w64 GCC tool-chain? In other words, dynamic libraries generated for MSVC and static libraries generated for GCC?</p>