Link errors using cryptopp on VS2012 static library, console application and clr program
<p>I have the following project structure on VS2012 C++:</p>

<p><code>cryptopp</code>: As downloaded and build from cryptopp project.</p>

<p><code>AccessLib</code>: A static library build using cryptopp functions. </p>

<p><code>TestApp</code>: A Win32 console application that uses AccessLib (and cryptolib indirectly)</p>

<p><code>UserApp</code>: A Windows interactive application with CLR support (<code>/clr</code>) that uses AccessLib (and cryptolib indirectly)</p>

<p>Well, my first try was to make this solution work to build my console application and my windows application. BTW, <code>cryptopp</code> was build in a way described in manuals and  <a href="https://stackoverflow.com/questions/6619042/how-do-i-install-crypto-in-visual-studio-2010">this SO link</a>. All tests from cryptopp project are running fine in the build environment.</p>

<p>Here is how I´ve build my project:</p>

<ul>
<li><p>Set <code>AccessLib</code> as being <code>/Mtd</code> or <code>/MT</code> for Debug or Release respectively, linking with <code>cryptolib.lib</code> from <code>cryptodir\Win32\Output\Debug</code> and <code>cryptodir\Win32\Output\Release</code>respectively.</p></li>
<li><p>Set <code>TestApp</code> as being also <code>/MTd</code> or <code>/MT</code> for Debug or Release respectively, linking to <code>AccessLib.lib</code> generated from step above.</p></li>
</ul>

<p>Fine till now, but when building <code>UserApp</code>it does not work as <code>TestApp</code> needs <code>/clr</code> and that´s incompatible with <code>MTd</code>or <code>/MT</code>. </p>

<p>So, here goes my first question: I can´t have a CLR program that links to a static library that has <code>/MTd</code>or <code>/MT</code>.... What should I do to build my <code>/clr</code> program to my static library <code>AccessLib.lib</code> that access <code>cryptopp</code> as a static library also ? Should I need to convert everything to DLL project ?</p>

<p>Well, I even tried to convert to use cryptopp as a DLL, that way:</p>

<ul>
<li>Set <code>AccessLib</code> as being <code>/MDd</code> or <code>/MD</code> for Debug or Release respectively, linking with <code>cryptolib.lib</code> from <code>cryptodir\Win32\DLL_Output\Debug</code> and <code>cryptodir\Win32\DLL_Output\Release</code>respectively.</li>
</ul>

<p>That step went fine, but when trying to build <code>TestApp</code> as being also <code>/MDd</code> or <code>/MD</code> for Debug or Release respectively, linking to <code>AccessLib.lib</code> generated from step above, I got several errors like:</p>

<pre><code> 1&gt;------ Build started: Project: TestApp, Configuration: Debug Win32 ------
1&gt;cryptlib.lib(hrtimer.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in TestApp.obj
1&gt;cryptlib.lib(pch.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in TestApp.obj
1&gt;msvcprtd.lib(MSVCP110D.dll) : error LNK2005: "public: __thiscall std::_Container_base12::_Container_base12(void)" (??0_Container_base12@std@@QAE@XZ) already defined in cryptlib.lib(hrtimer.obj)
1&gt;msvcprtd.lib(MSVCP110D.dll) : error LNK2005: "public: __thiscall std::_Container_base12::~_Container_base12(void)" (??1_Container_base12@std@@QAE@XZ) already defined in cryptlib.lib(hrtimer.obj)
1&gt;msvcprtd.lib(MSVCP110D.dll) : error LNK2005: "public: void __thiscall std::_Container_base12::_Orphan_all(void)" (?_Orphan_all@_Container_base12@std@@QAEXXZ) already defined in cryptlib.lib(hrtimer.obj)
1&gt;msvcprtd.lib(MSVCP110D.dll) : error LNK2005: "public: __thiscall std::locale::id::id(unsigned int)" (??0id@locale@std@@QAE@I@Z) already defined in cryptlib.lib(pch.obj)
1&gt;cryptopp.lib(cryptopp.dll) : error LNK2005: "public: unsigned char * __thiscall CryptoPP::AllocatorWithCleanup&lt;unsigned char,0&gt;::allocate(unsigned int,void const *)" (?allocate@?$AllocatorWithCleanup@E$0A@@CryptoPP@@QAEPAEIPBX@Z) already defined in accesslib.lib(Encryptor.obj)
1&gt;cryptopp.lib(cryptopp.dll) : error LNK2005: "public: void __thiscall CryptoPP::AllocatorWithCleanup&lt;unsigned char,0&gt;::deallocate(void *,unsigned int)" (?deallocate@?$AllocatorWithCleanup@E$0A@@CryptoPP@@QAEXPAXI@Z) already defined in accesslib.lib(Encryptor.obj)
1&gt;cryptopp.lib(cryptopp.dll) : error LNK2005: "public: unsigned char * __thiscall CryptoPP::AllocatorWithCleanup&lt;unsigned char,0&gt;::reallocate(unsigned char *,unsigned int,unsigned int,bool)" (?reallocate@?$AllocatorWithCleanup@E$0A@@CryptoPP@@QAEPAEPAEII_N@Z) already defined in accesslib.lib(Encryptor.obj)
1&gt;cryptopp.lib(cryptopp.dll) : error LNK2005: "public: __thiscall CryptoPP::AllocatorWithCleanup&lt;unsigned char,0&gt;::AllocatorWithCleanup&lt;unsigned char,0&gt;(void)" (??0?$AllocatorWithCleanup@E$0A@@CryptoPP@@QAE@XZ) already defined in accesslib.lib(Encryptor.obj)
1&gt;cryptopp.lib(cryptopp.dll) : error LNK2005: "public: __thiscall CryptoPP::Rijndael::Enc::Enc(void)" (??0Enc@Rijndael@CryptoPP@@QAE@XZ) already defined in accesslib.lib(Encryptor.obj)
1&gt;cryptopp.lib(cryptopp.dll) : error LNK2005: "public: virtual __thiscall CryptoPP::Rijndael::Enc::~Enc(void)" (??1Enc@Rijndael@CryptoPP@@UAE@XZ) already defined in accesslib.lib(Encryptor.obj)
1&gt;cryptopp.lib(cryptopp.dll) : error LNK2005: "public: __thiscall CryptoPP::Rijndael::Enc::Enc(class CryptoPP::Rijndael::Enc const &amp;)" (??0Enc@Rijndael@CryptoPP@@QAE@ABV012@@Z) already defined in accesslib.lib(Encryptor.obj)
1&gt;cryptopp.lib(cryptopp.dll) : error LNK2005: "public: static char const * __cdecl CryptoPP::CBC_ModeBase::StaticAlgorithmName(void)" (?StaticAlgorithmName@CBC_ModeBase@CryptoPP@@SAPBDXZ) already defined in accesslib.lib(Encryptor.obj)
1&gt;cryptopp.lib(cryptopp.dll) : error LNK2005: "public: __thiscall CryptoPP::CBC_Encryption::CBC_Encryption(void)" (??0CBC_Encryption@CryptoPP@@QAE@XZ) already defined in accesslib.lib(Encryptor.obj)
1&gt;cryptopp.lib(cryptopp.dll) : error LNK2005: "public: virtual __thiscall CryptoPP::CBC_Encryption::~CBC_Encryption(void)" (??1CBC_Encryption@CryptoPP@@UAE@XZ) already defined in accesslib.lib(Encryptor.obj)
1&gt;cryptopp.lib(cryptopp.dll) : error LNK2005: "public: virtual __thiscall CryptoPP::StreamTransformationFilter::~StreamTransformationFilter(void)" (??1StreamTransformationFilter@CryptoPP@@UAE@XZ) already defined in accesslib.lib(Encryptor.obj)
1&gt;cryptopp.lib(cryptopp.dll) : error LNK2005: "public: __thiscall CryptoPP::StringSinkTemplate&lt;class std::basic_string&lt;char,struct std::char_traits&lt;char&gt;,class std::allocator&lt;char&gt; &gt; &gt;::StringSinkTemplate&lt;class std::basic_string&lt;char,struct std::char_traits&lt;char&gt;,class std::allocator&lt;char&gt; &gt; &gt;(class std::basic_string&lt;char,struct std::char_traits&lt;char&gt;,class std::allocator&lt;char&gt; &gt; &amp;)" (??0?$StringSinkTemplate@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@CryptoPP@@QAE@AAV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) already defined in accesslib.lib(Encryptor.obj)
1&gt;cryptopp.lib(cryptopp.dll) : error LNK2005: "public: virtual __thiscall CryptoPP::StringSinkTemplate&lt;class std::basic_string&lt;char,struct std::char_traits&lt;char&gt;,class std::allocator&lt;char&gt; &gt; &gt;::~StringSinkTemplate&lt;class std::basic_string&lt;char,struct std::char_traits&lt;char&gt;,class std::allocator&lt;char&gt; &gt; &gt;(void)" (??1?$StringSinkTemplate@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@CryptoPP@@UAE@XZ) already defined in accesslib.lib(Encryptor.obj)
1&gt;cryptopp.lib(cryptopp.dll) : error LNK2005: "public: __thiscall CryptoPP::Exception::Exception(enum CryptoPP::Exception::ErrorType,class std::basic_string&lt;char,struct std::char_traits&lt;char&gt;,class std::allocator&lt;char&gt; &gt; const &amp;)" (??0Exception@CryptoPP@@QAE@W4ErrorType@01@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) already defined in accesslib.lib(Encryptor.obj)
1&gt;LINK : warning LNK4098: defaultlib 'LIBCMTD' conflicts with use of other libs; use /NODEFAULTLIB:library
1&gt;accesslib.lib(Encryptor.obj) : error LNK2001: unresolved external symbol "class CryptoPP::NameValuePairs const &amp; const CryptoPP::g_nullNameValuePairs" (?g_nullNameValuePairs@CryptoPP@@3ABVNameValuePairs@1@B)
1&gt;c:\project\dev\accesslib\Debug\TestApp.exe : fatal error LNK1120: 1 unresolved externals
========== Build: 0 succeeded, 1 failed, 1 up-to-date, 0 skipped ==========
</code></pre>

<p>I did not move to build <code>UserApp</code> with that configuration.</p>

<p>Help is appreciated to make this whole thing work together. I want to avoid usage of DLL´s at all. My original idea is to have everything as static libraries, but I don´t know if I can achieve that on that solution configuration.</p>

<p>Help appreciated.</p>