dimanche 27 septembre 2015

Linking error with boost::math and Xcode - Undefined symbols for architecture x86_64

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.

The error thrown by Xcode is:

Undefined symbols for architecture x86_64: "boost::math::tools::promote_args::type boost::math::beta(int, int, int)", referenced from: _main in main.o

ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation)

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.

The first thing I tried was from: http://ift.tt/1LfWo7r

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).

I then saw a number of stackoverflow responses with similar suggestions:

Boost Xcode C++ command line Undefined symbols for architecture x86_64

Using Boost on XCode 5 - Apple LLVM 5.0

Linking troubles with boost::program_options on OSX using LLVM

These responses seem to suggest that I needed to recompile boost with clang and std11 flags. I did this with:

./bootstrap.sh toolset=clang --with-libraries=math

./b2 toolset=clang cxxflags="-std=c++11 -stdlib=libc++" variant=release linkflags="-stdlib=libc++" link=static stage

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.

For reference, the line that throws the error is:

double ell = boost::math::beta(2, 2, 1);

At the top I have included:

boost/math/special_functions/gamma.hpp

boost/math/tr1.hpp

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.

Aucun commentaire:

Enregistrer un commentaire