title: Dynamic linking boost libraries and the auto-link not working properly?
body: <p>I used the following command to build <code>boost-1.53.0</code> on <code>Win7 Pro</code> with <code>VS 2013 Pro (VC12.0, 18.00.21005.1)</code>:</p>
  
  <pre><code>b2 stage toolset=msvc link=shared runtime-link=shared threading=multi --without-graph --without-graph_parallel --without-mpi --without-wave --without-python
  </code></pre>
  
  <p>And before that, I patched my source code as per this patch: <a href="https://svn.boost.org/trac/boost/attachment/ticket/8750/for_vs2013.patch" rel="nofollow">#8750 for_vs2013.patch</a>.</p>
  
  <p>Finally I got the files under <code>$BOOST_ROOT/stage/lib</code> like these:</p>
  
  <pre><code>boost_atomic-vc120-mt-1_53.dll
  boost_atomic-vc120-mt-1_53.lib
  boost_atomic-vc120-mt-gd-1_53.dll
  boost_atomic-vc120-mt-gd-1_53.lib
  ...
  boost_thread-vc120-mt-1_53.dll
  boost_thread-vc120-mt-1_53.lib
  boost_thread-vc120-mt-gd-1_53.dll
  boost_thread-vc120-mt-gd-1_53.lib
  ...
  // only theses four files have "lib" prefix
  libboost_exception-vc120-mt-1_53.lib
  libboost_exception-vc120-mt-gd-1_53.lib
  libboost_test_exec_monitor-vc120-mt-1_53.lib
  libboost_test_exec_monitor-vc120-mt-gd-1_53.lib
  </code></pre>
  
  <p>I failed building <code>boost::signals</code> library. Since I don't know whether it's relative to this issue, I clarify it here.</p>
  
  <p>I wrote a very simple demo to learn <code>boost::thread</code> according a tutorial just now. But the compiler gives me a link error: <code>LINK : fatal error LNK1104: cannot open file 'libboost_thread-vc120-mt-gd-1_53.lib'</code>. I searched around and I have a question. I'm sure I've set <code>Project Properties &gt; C/C++ &gt; Code Generation &gt; Runtime Library</code> to <code>/MDd</code>. But why the compiler still tries to link the static library <code>libboost_thread-vc120-mt-gd-1_53.lib</code> when I rebuild the project? I also tried to use some relative solutions that I found, such as using <code>BOOST_ALL_DYN_LINK</code> or <code>BOOST_DYN_LINK</code> precompile directive. But it's not working. I found such a snippet in <code>auto-link.hpp</code>:</p>
  
  <pre><code>//
  // select linkage opt:
  //
  #if (defined(_DLL) || defined(_RTLDLL)) &amp;&amp; defined(BOOST_DYN_LINK)
  #  define BOOST_LIB_PREFIX
  #elif defined(BOOST_DYN_LINK)
  #  error "Mixing a dll boost library with a static runtime is a really bad idea..."
  #else
  #  define BOOST_LIB_PREFIX "lib"
  #endif
  </code></pre>
  
  <p>It should work but I can't get the result I want :(</p>
  
  <p>BTW, should I rebuild the boost libraries with <code>link=static</code> option?</p>
  
  <h2>demo code</h2>
  
  <pre><code>// c++ std libraries
  #include &lt;iostream&gt;
  // c++ boost libraries
  #include &lt;boost/thread.hpp&gt;
  #include &lt;boost/date_time.hpp&gt;
  
  // #define BOOST_ALL_DYN_LINK
  // #define BOOST_DYN_LINK
  
  void WorkerFunc()
  {
      boost::posix_time::seconds worktime(3);
      std::cout &lt;&lt; "Worker: running..." &lt;&lt; std::endl;
  
      // Pretend to do sth. useful...
      boost::this_thread::sleep(worktime);
  
      std::cout &lt;&lt; "Worker: finished." &lt;&lt; std::endl;
  }
  
  
  int main()
  {
      std::cout &lt;&lt; "main: startup." &lt;&lt; std::endl;
      // Create a worker thread.
      boost::thread worker_thread(WorkerFunc);
  
      std::cout &lt;&lt; "main: waiting for thread..." &lt;&lt; std::endl;
      worker_thread.join();
  
      std::cout &lt;&lt; "main: done." &lt;&lt; std::endl;
  
      return 0;
  }
  </code></pre>