title: How to statically link using link.exe
body: <p>I've been trying to statically link against a C++ library called <a href="http://pocoproject.org/" rel="nofollow noreferrer">Poco</a> on Windows using the Visual Studio 2008 command line tools.</p>
  
  <p>I build my program with:</p>
  
  <pre><code>cl /I..\poco\lib /c myapp.cpp
  link /libpath:..\poco\lib myapp.obj PocoNet.lib
  </code></pre>
  
  <p>This results in an exe that at runtime requires PocoNet.dll and PocoFoundation.dll.</p>
  
  <p>I spent some time reading up on linking in Windows, and learned that <code>cl /MT</code> statically links against the standard library, while <code>cl /MD</code> links dynamically.</p>
  
  <p>I tried to specify <code>/MT</code>, but that didn't seem to change anything; my app still requires the Poco DLLs. (I also suspect that <code>/MT</code> is the default behavior.)</p>
  
  <p>Looking under <code>..\poco\lib</code>, I found there was also a PocoNetmt.lib, but specifying that instead of PocoNet.lib resulted in a bunch of LNK2005 errors ("already defined"):</p>
  
  <pre><code>msvcprt.lib(MSVCP90.dll) : error LNK2005: "public: __thiscall std::basic_string&lt;char,struct std::char_traits&lt;char&gt;,class std::allocator&lt;char&gt; &gt;::~basic_string&lt;char,struct std::char_traits&lt;char&gt;,class std::allocator&lt;char&gt; &gt;(void)" (??1?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@XZ) already defined in exp.obj
  </code></pre>
  
  <p>I then tried stacking on more flags:</p>
  
  <ul>
  <li><p><code>/verbose:lib</code>: useful for seeing what's happening</p></li>
  <li><p><code>/Zl</code>: same results as before</p></li>
  <li><p><code>/nodefaultlib:libcmt.lib /nodefaultlib:msvcprt.lib</code>: got this error:</p>
  
  <pre><code>PocoFoundationmt.lib(Exception.obj) : warning LNK4217: locally defined symbol ??1?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@XZ (public: __thiscall std::basic_string&lt;char,struct std::char_traits&lt;char&gt;,class std::allocator&lt;char&gt; &gt;::~basic_string&lt;char,struct std::char_traits&lt;char&gt;,class std::allocator&lt;char&gt; &gt;(void)) imported in function __ehhandler$??0Exception@Poco@@QAE@ABV01@@Z
  </code></pre></li>
  <li><p>dropping the <code>.lib</code> altogether, <a href="https://stackoverflow.com/questions/37398/how-do-i-make-a-fully-statically-linked-exe-with-visual-studio-express-2005">as suggested here</a>: same error as above</p></li>
  </ul>
  
  <p>I also tried some combinations of the above, all to no avail.</p>
  
  <p>Any clues would be greatly appreciated. But just as useful would be any pointers to resources that are useful for debugging (or learning about) these types of issues.</p>