title: Dynamic linking error with statically linked boost library
body: <p>I am on Windows(MSVC 2012) and with Boost v1.54, I compiled <strong>Boost.Log</strong> (my small project depends on it) with following parameters:</p>
  
  <pre><code>b2.exe link=static variant=release runtime-link=shared --with-log stage
  </code></pre>
  
  <p>So the log module is compiled and dynamically linked to C Runtime Library.</p>
  
  <p>Then my small project uses <strong>CMake</strong> to manage, and I add option to link boost statically:</p>
  
  <pre><code>set(Boost_USE_STATIC_LIBS ON)
  </code></pre>
  
  <p>But make process of generated nmake makefile failed, with link error 2038:</p>
  
  <pre><code>libboost_log-vc110-mt-1_54.lib(attribute_set.obj):-1: error: LNK2038:
    mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't
    match value 'MT_StaticRelease' in http_proxy_server.cpp.obj
  </code></pre>
  
  <p>But if I compile boost with option <code>runtime-link=static</code>, means linking CRT statically, then I can successfully make my project.</p>
  
  <p>My question is: Could someone explain why my project failed to link with the CRT dynamically linked version of boost, but succeeded with the CRT statically linked version of boost, what's the difference?</p>
  
  <p>BTW: my project is dynamically linked to CRT with <code>/MD</code> option.</p>
  
  <hr>
  
  <p><strong>Edit:</strong></p>
  
  <p>Finally I figured out the reason, I mixed up <code>CMAKE_CXX_FLAGS_RELEASE</code> with <code>CMAKE_CXX_FLAGS</code>, the former has a <code>/MD</code> option, but the latter does not. In fact cmake will pass the latter to compiler, so my program is actually linked statically as the error output shows.</p>
  
  <p>Solution: run cmake with <code>-DCMAKE_BUILD_TYPE=Release</code> when generating makefile, this will add options of <code>CMAKE_CXX_FLAGS_RELEASE</code> into <code>CMAKE_CXX_FLAGS</code> automatically, then the program will be linked to CRT dynamically.</p>
  
  <p>Oh, a silly question.</p>