title: Linking error with boost::math and Xcode - Undefined symbols for architecture x86_64
body: <p>I'm having some trouble linking a boost library to my C++ program in Xcode 7.0.  I am running OSX 10.10.5 and I downloaded Boost 1.59.0.</p>
  
  <p>The error thrown by Xcode is:</p>
  
  <blockquote>
    <p>Undefined symbols for architecture x86_64:
      "boost::math::tools::promote_args::type boost::math::beta(int, int, int)", referenced from:
          _main in main.o</p>
    
    <p>ld: symbol(s) not found for architecture x86_64
    clang: error: linker command failed with exit code 1 (use -v to see invocation)</p>
  </blockquote>
  
  <p>After googling for most of the day, I saw that a number of people have had similar issues, but none of the fixes worked for me.  </p>
  
  <p>The first thing I tried was from:
  <a href="http://www.nullptr.me/2014/08/20/boost-with-xcode/" rel="nofollow noreferrer">http://www.nullptr.me/2014/08/20/boost-with-xcode/</a></p>
  
  <p>I changed my search paths in Xcode to the appropriate directory and under "Other Linker Flags" I added "-L/usr/local/lib -lboost_math_c99 -lboost_math_tr1".  This gave me the same error.  Curiously, everything ran fine when I copied the exact code from the blogger above (so linking the chrono and system libraries from boost was ok, but as soon as I tried to use a function from math again, it threw the error).  </p>
  
  <p>I then saw a number of stackoverflow responses with similar suggestions: </p>
  
  <p><a href="https://stackoverflow.com/questions/21590507/boost-xcode-c-command-line-undefined-symbols-for-architecture-x86-64">Boost Xcode C++ command line Undefined symbols for architecture x86_64</a></p>
  
  <p><a href="https://stackoverflow.com/questions/18888327/using-boost-on-xcode-5-apple-llvm-5-0">Using Boost on XCode 5 - Apple LLVM 5.0</a></p>
  
  <p><a href="https://stackoverflow.com/questions/11081818/linking-troubles-with-boostprogram-options-on-osx-using-llvm">Linking troubles with boost::program_options on OSX using LLVM</a></p>
  
  <p>These responses seem to suggest that I needed to recompile boost with clang and std11 flags.  I did this with:</p>
  
  <blockquote>
    <p>./bootstrap.sh toolset=clang --with-libraries=math</p>
    
    <p>./b2 toolset=clang cxxflags="-std=c++11
     -stdlib=libc++" variant=release linkflags="-stdlib=libc++" link=static stage</p>
  </blockquote>
  
  <p>and then I put the new libraries where they were expected.  However again when I tried to build in Xcode, I got the exact same error.</p>
  
  <p>For reference, the line that throws the error is:</p>
  
  <blockquote>
    <p>double ell = boost::math::beta(2, 2, 1);</p>
  </blockquote>
  
  <p>At the top I have included:</p>
  
  <blockquote>
    <p>boost/math/special_functions/gamma.hpp</p>
    
    <p>boost/math/tr1.hpp</p>
  </blockquote>
  
  <p>Any help would be greatly appreciated.  It's hard for me to understand why I can use the chrono and system libraries from boost without trouble, but math throws an error.  I am a statistician and my goal is to speed up an R package, but I need the beta function, which seems to be most easily accessible through boost.  Please let me know if I can provide any more information.</p>