title: How to use Boost C++ Libraries on MacOS
body: <p>I am trying to use Boost Libraries on MacOS.</p>
  
  <p>I installed boost using <code>brew install boost</code>. This installed boost in <code>usr/local/Cellar/boost</code>. </p>
  
  <p>I compiled 2 programs with the same command <code>g++ --std=c++11 main.cpp -o main</code> and then <code>./main</code></p>
  
  <p>However the first one compiled successfully while the second one doesn't. What should I do?</p>
  
  <p>Program1.</p>
  
  <pre><code>#include &lt;boost/lambda/lambda.hpp&gt;
  #include &lt;iostream&gt;
  #include &lt;iterator&gt;
  #include &lt;algorithm&gt;
  
  int main()
  {
      using namespace boost::lambda;
      typedef std::istream_iterator&lt;int&gt; in;
  
      std::for_each(
          in(std::cin), in(), std::cout &lt;&lt; (_1 * 3) &lt;&lt; " " );
  }
  </code></pre>
  
  <p>Program2.</p>
  
  <pre><code>#include &lt;boost/test/unit_test.hpp&gt;
  
  int add( int i, int j ) { return i+j; }
  
  BOOST_AUTO_TEST_CASE( my_test )
  {
      BOOST_CHECK( add( 2,2 ) == 4 );       
  
      BOOST_REQUIRE( add( 2,2 ) == 4 );     
  
      if( add( 2,2 ) != 4 )
        BOOST_ERROR( "Ouch..." );      
  
      if( add( 2,2 ) != 4 )
        BOOST_FAIL( "Ouch..." );           
  
      if( add( 2,2 ) != 4 ) throw "Ouch..."; 
  
      BOOST_CHECK_MESSAGE( add( 2,2 ) == 4, 
                           "add(..) result: " &lt;&lt; add( 2,2 ) );
  
      BOOST_CHECK_EQUAL( add( 2,2 ), 4 );  
  }
  </code></pre>
  
  <p>I get the following error when I compile program 2.</p>
  
  <pre><code>Undefined symbols for architecture x86_64:
    "boost::test_tools::tt_detail::report_assertion(boost::test_tools::assertion_result const&amp;, boost::unit_test::lazy_ostream const&amp;, boost::unit_test::basic_cstr
  ing&lt;char const&gt;, unsigned long, boost::test_tools::tt_detail::tool_level, boost::test_tools::tt_detail::check_type, unsigned long, ...)", referenced from:
        my_test::test_method() in del-9b4dcb.o
  
        bool boost::test_tools::tt_detail::check_frwd&lt;boost::test_tools::tt_detail::equal_impl_frwd, int, int&gt;(boost::test_tools::tt_detail::equal_impl_frwd, boost
  ::unit_test::lazy_ostream const&amp;, boost::unit_test::basic_cstring&lt;char const&gt;, unsigned long, boost::test_tools::tt_detail::tool_level, boost::test_tools::tt_det
  ail::check_type, int const&amp;, char const*, int const&amp;, char const*) in del-9b4dcb.o
    "boost::unit_test::unit_test_log_t::set_checkpoint(boost::unit_test::basic_cstring&lt;char const&gt;, unsigned long, boost::unit_test::basic_cstring&lt;char const&gt;)", r
  eferenced from:
        my_test_invoker() in del-9b4dcb.o
        my_test::test_method() in del-9b4dcb.o
    "boost::unit_test::test_case::test_case(boost::unit_test::basic_cstring&lt;char const&gt;, boost::unit_test::basic_cstring&lt;char const&gt;, unsigned long, boost::functio
  n&lt;void ()&gt; const&amp;)", referenced from:
        boost::unit_test::make_test_case(boost::function&lt;void ()&gt; const&amp;, boost::unit_test::basic_cstring&lt;char const&gt;, boost::unit_test::basic_cstring&lt;char const&gt;,
   unsigned long) in del-9b4dcb.o
    "boost::unit_test::ut_detail::auto_test_unit_registrar::auto_test_unit_registrar(boost::unit_test::test_case*, boost::unit_test::decorator::collector&amp;, unsigne
  d long)", referenced from:
        ___cxx_global_var_init.1 in del-9b4dcb.o
    "boost::unit_test::ut_detail::normalize_test_case_name(boost::unit_test::basic_cstring&lt;char const&gt;)", referenced from:
        boost::unit_test::make_test_case(boost::function&lt;void ()&gt; const&amp;, boost::unit_test::basic_cstring&lt;char const&gt;, boost::unit_test::basic_cstring&lt;char const&gt;,
   unsigned long) in del-9b4dcb.o
    "vtable for boost::unit_test::unit_test_log_t", referenced from:
        boost::unit_test::unit_test_log_t::unit_test_log_t() in del-9b4dcb.o
    NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
    "_main", referenced from:
       implicit entry/start for main executable
  ld: symbol(s) not found for architecture x86_64
  clang: error: linker command failed with exit code 1 (use -v to see invocation)
  </code></pre>