title: Linking Boost Library in Linux
body: <p>I am trying to build a project using Boost's Asio and I am having some trouble.  Initially, I tried to build the project without any additional libraries since everything is supposedly in the header files.</p>
  
  <p>The program I am trying to build looks like this:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;boost/asio.hpp&gt;
  #include &lt;boost/date_time/posix_time/posix_time.hpp&gt;
  
  int main()
  {
      boost::asio::io_service io;
      boost::asio::deadline_timer t(io, boost::posix_time::seconds(5));
  
      t.wait();
  
      std::cout &lt;&lt; "Hello, world!" &lt;&lt; std::endl;
  
      return 0;
  }
  </code></pre>
  
  <p>It can be found <a href="http://www.boost.org/doc/libs/1_37_0/doc/html/boost_asio/tutorial/tuttimer1.html" rel="noreferrer">here</a> on Boost's website.</p>
  
  <p>So, initially I just had:</p>
  
  <pre><code>-I /usr/include/boost_1_40_0
  </code></pre>
  
  <p>This resulted in the following errors:</p>
  
  <pre><code>make -k all
  Building target: HelloWorld
  Invoking: GCC C++ Linker
  g++  -o"HelloWorld"  ./main.o  
  ./main.o: In function `__static_initialization_and_destruction_0':
  /usr/include/boost_1_40_0/boost/system/error_code.hpp:205: undefined reference to `boost::system::get_system_category()'
  /usr/include/boost_1_40_0/boost/system/error_code.hpp:206: undefined reference to `boost::system::get_generic_category()'
  /usr/include/boost_1_40_0/boost/system/error_code.hpp:211: undefined reference to `boost::system::get_generic_category()'
  /usr/include/boost_1_40_0/boost/system/error_code.hpp:212: undefined reference to `boost::system::get_generic_category()'
  /usr/include/boost_1_40_0/boost/system/error_code.hpp:213: undefined reference to `boost::system::get_system_category()'
  ./main.o: In function `boost::asio::error::get_system_category()':
  /usr/include/boost_1_40_0/boost/asio/error.hpp:218: undefined reference to `boost::system::get_system_category()'
  ./main.o: In function `error_code':
  /usr/include/boost_1_40_0/boost/system/error_code.hpp:312: undefined reference to `boost::system::get_system_category()'
  ./main.o: In function `posix_tss_ptr':
  /usr/include/boost_1_40_0/boost/asio/detail/posix_tss_ptr.hpp:47: undefined reference to `pthread_key_create'
  ./main.o: In function `~posix_tss_ptr':
  /usr/include/boost_1_40_0/boost/asio/detail/posix_tss_ptr.hpp:61: undefined reference to `pthread_key_delete'
  ./main.o: In function `boost::asio::detail::posix_thread::join()':
  /usr/include/boost_1_40_0/boost/asio/detail/posix_thread.hpp:77: undefined reference to `pthread_join'
  ./main.o: In function `~posix_thread':
  /usr/include/boost_1_40_0/boost/asio/detail/posix_thread.hpp:69: undefined reference to `pthread_detach'
  collect2: ld returned 1 exit status
  make: *** [HelloWorld] Error 1
  make: Target `all' not remade because of errors.
  </code></pre>
  
  <p>It appeared that I needed the system library.  So, I followed the directions on the Getting Started guide found <a href="http://boost.org/doc/libs/1_40_0/more/getting_started/unix-variants.html" rel="noreferrer">here</a>, which gave me a bunch of libraries located in <em>/usr/include/boost_1_40_0/stage/lib</em>.  Among them was <em>libboost_system.a</em>.  Thus, I attempted to compile with:</p>
  
  <pre><code>-I /usr/include/boost_1_40_0
  -L /usr/include/boost_1_40_0/stage/lib
  -l libboost_system
  </code></pre>
  
  <p>However, I got this:</p>
  
  <pre><code>make -k all
  Building target: HelloWorld
  Invoking: GCC C++ Linker
  g++ -L/usr/lib -L/usr/include/boost_1_40_0/stage/lib -o"HelloWorld"  ./main.o   -llibboost_system
  /usr/bin/ld: cannot find -llibboost_system
  collect2: ld returned 1 exit status
  make: *** [HelloWorld] Error 1
  make: Target `all' not remade because of errors.
  </code></pre>
  
  <p>I'm not sure why, but it can't seem to identify the library or any of the others that I try.  What might I be doing incorrectly?  Thanks in advance!</p>