title: Link Error : xxx is already defined in *****.LIB :: What exactly is wrong?
body: <p><strong>Problem:</strong></p>
  
  <p>I'm trying to use a library named <a href="http://dicom.offis.de/dcmtk" rel="nofollow noreferrer">DCMTK</a> which used some other external libraries ( zlib, libtiff, libpng, libxml2, libiconv ). I've downloaded these external libraries (*.LIB &amp; *.h files ) from the same website. Now, when I compile the DCMTK library I'm getting link errors (793 errors) like this:</p>
  
  <pre><code>Error   2   error LNK2005: __encode_pointer already defined in MSVCRTD.lib(MSVCR90D.dll)    LIBCMTD.lib dcmmkdir 
  Error   3   error LNK2005: __decode_pointer already defined in MSVCRTD.lib(MSVCR90D.dll)    LIBCMTD.lib dcmmkdir 
  Error   4   error LNK2005: __CrtSetCheckCount already defined in MSVCRTD.lib(MSVCR90D.dll)  LIBCMTD.lib dcmmkdir 
  Error   5   error LNK2005: __invoke_watson already defined in MSVCRTD.lib(MSVCR90D.dll) LIBCMTD.lib dcmmkdir 
  Error   6   error LNK2005: __errno already defined in MSVCRTD.lib(MSVCR90D.dll) LIBCMTD.lib dcmmkdir 
  Error   7   error LNK2005: __configthreadlocale already defined in MSVCRTD.lib(MSVCR90D.dll)    LIBCMTD.lib dcmmkdir 
  Error   8   error LNK2005: _exit already defined in MSVCRTD.lib(MSVCR90D.dll)   LIBCMTD.lib dcmmkdir 
  </code></pre>
  
  <p><strong>Documentation:</strong></p>
  
  <p>This seems to be a popular error for this library so, they do have a FAQ entry addressing this issue which ( <a href="http://forum.dcmtk.org/viewtopic.php?t=35" rel="nofollow noreferrer">http://forum.dcmtk.org/viewtopic.php?t=35</a> ) says:</p>
  
  <blockquote>
    <ul>
    <li>The problem is that the linker tries to combine <em>different,
    incompatible versions</em> of the Visual
    C++ runtime library into a single
    binary. </li>
    <li>This happens when not all parts of your project and the libraries you
    link against are generated with the
    same code generation options in Visual
    C++. </li>
    <li><p>Do not use the /NODEFAULTLIB workaround, because strange software
    crashes may follow. Fix the problem! </p></li>
    <li><p>DCMTK is by default compiled with the "Multithreaded" or "Multithreaded
    Debug" code generation option (the
    latter for Debug mode). </p></li>
    <li>Either change the project settings of all of your code to use these code
    generation options, </li>
    <li>or change the code generation for all DCMTK modules and re-compile. </li>
    <li>MFC users beware: DCMTK should be compiled with "Multithreaded DLL" or
    "Multithreaded DLL Debug" settings if
    you want to link the libraries into an
    MFC application.</li>
    </ul>
  </blockquote>
  
  <p><strong>Solution to same problem for others:</strong></p>
  
  <p><a href="https://stackoverflow.com/questions/2259697/vscopengl-huge-amount-of-linker-issues-with-release-build-only">Huge Amount of Linker Issues with Release Build Only</a> says:</p>
  
  <blockquote>
    <p>It seems that your release build is
    trying to link to something that was
    built debug. You probably have a
    broken dependency in your build, (or
    you missed rebuilding something to
    release by hand if your project is
    normally built in pieces).</p>
    
    <p>More technically, you seem to be
    linking projects built with different
    <code>C Run Time library</code> settings, one
    with "Multi-Threaded", another one
    with "Multi-Threaded Debug". Adjust
    the settings for all the projects to
    use the very same flavour of the
    library and the issue should go away</p>
  </blockquote>
  
  <p><strong>Questions:</strong></p>
  
  <p>Till now I used to think that Name mangling is the only problem that may cause linking failures if its not been standardized. Just now I knew there are other things also which can cause same effect.</p>
  
  <ol>
  <li><p>Whats up with the "Debug Mode" (Multi-Threaded Debug) and "Release Mode" (Multi-Threaded)? What <em>exactly</em> is happening under the hood? Why <em>exactly</em> this thing is causing linking error?</p></li>
  <li><p>I wonder if there is something called "Single-Threaded Debug" and "Single-Threaded" which again causes the same thing.</p></li>
  <li><p>Documentation talks something about "Code Generation Options". What Code Generation Options? WTH are they?</p></li>
  <li><p>Documentation specifically warns us not to use /NODEFAULTLIB workaround. (example /NODEFAULTLIB :msvcrt ). Why? How would I cause troubles? what exactly is it? </p></li>
  <li>Please explain the last point in the documentation for MFC users. Because I'm going to use MFC later in this project. Explain Why should we do it? What troubles would it cause if I don't.</li>
  <li>Anything more you'd like to mention? I mean regarding similar errors. I'm very interested in Linker &amp; its problems. So, if there are any similar things you can mentions them or some keywords atleast.</li>
  </ol>