title: Building static libraries for windows using cygwin
body: <p>I'm trying to build <a href="http://www.cgal.org/" rel="nofollow noreferrer">CGAL</a> for windows to use in my project under Visual Studio 2010. CGAL requires <a href="http://gmplib.org/" rel="nofollow noreferrer">GMP</a> and <a href="http://www.mpfr.org/" rel="nofollow noreferrer">MPFR</a> libraries and provides them in distribution. However, it provides them as a lib+dll bundle, while I want them to be compiled statically in form of a single .lib file.</p>
  
  <p>So now I'm trying to build GMP and MPFR as a static library under windows. I'm using cygwin for this purpose as suggested <a href="http://www.cs.nyu.edu/exact/core/gmp/" rel="nofollow noreferrer">here</a>. After call to <code>configure</code> and <code>make</code> I have output libs with <code>.a</code> extension with additional <code>.la</code> file. I don't really know much about static libraries for Unix, so I suggested it is the same as <code>.lib</code> with just different extension. I renamed it to .lib and linked to my project - it fitted well.</p>
  
  <p><strong>The first question</strong>: was I correct doing so? Are the .a and .lib files really the same? I saw <a href="https://stackoverflow.com/questions/2636284/linkning-linux-static-libraries-in-windows-with-cygwin">this</a> question, but didn't find it useful enough.</p>
  
  <p>Then problem arose: I had</p>
  
  <pre><code>error LNK2019: unresolved external symbol ___getreent referenced in function ___gmp_default_reallocate
  </code></pre>
  
  <p>Seems like some cygwin functions are not linked in resulting <code>gmp.lib</code>. I found <a href="http://lucksus.eu/2009/02/12/cygwin-and-undefined-reference-to-__getreent/" rel="nofollow noreferrer">here</a>, that <code>getreent</code> may be exported from <code>libcygwin.a</code>. So I copied it to <code>libcygwin.lib</code> and linked to my project. Not surprisingly, I received the following error:</p>
  
  <pre><code>error LNK2005: _strcpy already defined in libcygwin.lib(t-d001719.o) in libcmtd.lib(strcat.obj) 
  </code></pre>
  
  <p>Of course, I cannot know what functions and how are declared in this library and seems like <code>strcpy</code> is conflicting with one from Visual Studio. What I really want to happen is <code>gmp.lib</code> would be smart enough to link this function statically. So,</p>
  
  <p><strong>The second question</strong>: how to force GMP to link library dependencies? <strong>or</strong> How to properly build GMP for windows without using cygwin?</p>