title: Static Compile of Thread Example
body: <p>I compiled the Boost C++ libraries as follows:</p>
  
  <pre><code>bjam install variant=release link=static threading=multi runtime-link=static
  </code></pre>
  
  <p>No errors. Then I compiled the following source:</p>
  
  <pre><code>#include &lt;boost/thread/thread.hpp&gt;
  #include &lt;iostream&gt;
  
  #define BOOST_THREAD_NO_LIB
  
  void hello() {
    std::cout &lt;&lt; "Hello world, I'm a thread!" &lt;&lt; std::endl;
  }
  
  int main(int argc, char* argv[]) {
    boost::thread thrd(&amp;hello);
    thrd.join();
    return 0;
  }
  </code></pre>
  
  <p>Using:</p>
  
  <pre><code>g++ -lboost_thread Thread.cpp
  </code></pre>
  
  <p>The program compiled and ran fine because the Boost libraries are found in <code>/usr/local/lib</code>. When I removed <code>/usr/local/lib</code> from <code>/etc/ld.so.conf.d/libc.conf</code> I ran into the following error (no surpise):</p>
  
  <pre><code>./a.out: error while loading shared libraries: libboost_thread.so.1.41.0: cannot
  open shared object file: No such file or directory
  </code></pre>
  
  <p>How do I compile <code>Thread.cpp</code> linking to Boost statically? I tried the following:</p>
  
  <pre><code>g++ -static -lboost_thread -lpthread Thread.cpp
  </code></pre>
  
  <p>I have the following Boost libraries installed:</p>
  
  <pre><code> ldconfig -v | grep boost
   libboost_unit_test_framework.so.1.41.0 -&gt; libboost_unit_test_framework.so.1.41.0
   libboost_math_tr1f.so.1.41.0 -&gt; libboost_math_tr1f.so.1.41.0
   libboost_prg_exec_monitor.so.1.41.0 -&gt; libboost_prg_exec_monitor.so.1.41.0
   libboost_math_c99.so.1.41.0 -&gt; libboost_math_c99.so.1.41.0
   libboost_regex.so.1.41.0 -&gt; libboost_regex.so.1.41.0
   libboost_signals.so.1.41.0 -&gt; libboost_signals.so.1.41.0
   libboost_python.so.1.41.0 -&gt; libboost_python.so.1.41.0
   libboost_serialization.so.1.41.0 -&gt; libboost_serialization.so.1.41.0
   libboost_graph.so.1.41.0 -&gt; libboost_graph.so.1.41.0
   libboost_date_time.so.1.41.0 -&gt; libboost_date_time.so.1.41.0
   libboost_thread.so.1.41.0 -&gt; libboost_thread.so.1.41.0
   libboost_math_c99l.so.1.41.0 -&gt; libboost_math_c99l.so.1.41.0
   libboost_math_tr1l.so.1.41.0 -&gt; libboost_math_tr1l.so.1.41.0
   libboost_wserialization.so.1.41.0 -&gt; libboost_wserialization.so.1.41.0
   libboost_system.so.1.41.0 -&gt; libboost_system.so.1.41.0
   libboost_math_tr1.so.1.41.0 -&gt; libboost_math_tr1.so.1.41.0
   libboost_math_c99f.so.1.41.0 -&gt; libboost_math_c99f.so.1.41.0
   libboost_wave.so.1.41.0 -&gt; libboost_wave.so.1.41.0
   libboost_filesystem.so.1.41.0 -&gt; libboost_filesystem.so.1.41.0
   libboost_program_options.so.1.41.0 -&gt; libboost_program_options.so.1.41.0
   libboost_program_options.so.1.35.0 -&gt; libboost_program_options.so.1.35.0
   libboost_program_options-mt.so.1.35.0 -&gt; libboost_program_options-mt.so.1.35.0
   libboost_thread-gcc42-mt-1_34_1.so.1.34.1 -&gt; libboost_thread-gcc42-mt-1_34_1.so.1.34.1
  </code></pre>
  
  <p>I receive the following compile errors:</p>
  
  <pre><code>/tmp/ccek8Br2.o: In function `main':
  Thread.cpp:(.text+0x10b): undefined reference to `boost::thread::join()'
  Thread.cpp:(.text+0x119): undefined reference to `boost::thread::~thread()'
  Thread.cpp:(.text+0x140): undefined reference to `boost::thread::~thread()'
  /tmp/ccek8Br2.o: In function `boost::mutex::mutex()':
  Thread.cpp:(.text._ZN5boost5mutexC1Ev[boost::mutex::mutex()]+0x22): undefined reference to `pthread_mutex_init'
  /tmp/ccek8Br2.o: In function `boost::detail::thread_data&lt;void (*)()&gt;::~thread_data()':
  Thread.cpp:(.text._ZN5boost6detail11thread_dataIPFvvEED0Ev[boost::detail::thread_data&lt;void (*)()&gt;::~thread_data()]+0x1c): undefined reference to `boost::detail::thread_data_base::~thread_data_base()'
  /tmp/ccek8Br2.o: In function `boost::detail::thread_data&lt;void (*)()&gt;::~thread_data()':
  Thread.cpp:(.text._ZN5boost6detail11thread_dataIPFvvEED1Ev[boost::detail::thread_data&lt;void (*)()&gt;::~thread_data()]+0x1c): undefined reference to `boost::detail::thread_data_base::~thread_data_base()'
  /tmp/ccek8Br2.o: In function `boost::condition_variable::condition_variable()':
  Thread.cpp:(.text._ZN5boost18condition_variableC1Ev[boost::condition_variable::condition_variable()]+0x17): undefined reference to `pthread_cond_init'
  /tmp/ccek8Br2.o: In function `boost::condition_variable::~condition_variable()':
  Thread.cpp:(.text._ZN5boost18condition_variableD1Ev[boost::condition_variable::~condition_variable()]+0x11): undefined reference to `pthread_cond_destroy'
  /tmp/ccek8Br2.o: In function `boost::mutex::~mutex()':
  Thread.cpp:(.text._ZN5boost5mutexD1Ev[boost::mutex::~mutex()]+0x11): undefined reference to `pthread_mutex_destroy'
  /tmp/ccek8Br2.o: In function `boost::detail::thread_data_base::thread_data_base()':
  Thread.cpp:(.text._ZN5boost6detail16thread_data_baseC2Ev[boost::detail::thread_data_base::thread_data_base()]+0x23): undefined reference to `vtable for boost::detail::thread_data_base'
  /tmp/ccek8Br2.o: In function `boost::thread::thread&lt;void (*)()&gt;(void (*)(), boost::disable_if&lt;boost::is_convertible&lt;void (*&amp;)(), boost::detail::thread_move_t&lt;void (*)()&gt; &gt;, boost::thread::dummy*&gt;::type)':
  Thread.cpp:(.text._ZN5boost6threadC1IPFvvEEET_NS_10disable_ifINS_14is_convertibleIRS4_NS_6detail13thread_move_tIS4_EEEEPNS0_5dummyEE4typeE[boost::thread::thread&lt;void (*)()&gt;(void (*)(), boost::disable_if&lt;boost::is_convertible&lt;void (*&amp;)(), boost::detail::thread_move_t&lt;void (*)()&gt; &gt;, boost::thread::dummy*&gt;::type)]+0x36): undefined reference to `boost::thread::start_thread()'
  /tmp/ccek8Br2.o:(.rodata._ZTIN5boost6detail11thread_dataIPFvvEEE[typeinfo for boost::detail::thread_data&lt;void (*)()&gt;]+0x10): undefined reference to `typeinfo for boost::detail::thread_data_base'
  collect2: ld returned 1 exit status
  </code></pre>
  
  <p>Any ideas?</p>