lundi 9 août 2021

Undefined Boost symbol when linking to pre-compiled QuantLib binaries on MacOS

I am trying to compile some C++ that depends on QuantLib, which in turn depends on Boost. I am working on a MacBook Pro M1 (ARM architecture). I installed Boost and QuantLib using the instructions on this page: https://www.quantlib.org/install/macosx.shtml. I then tried to compile the following source code:

#include <iostream>
#include <ql/quantlib.hpp>
 
int main(int, char*[])
{
    QuantLib::Option::Type OptionType(QuantLib::Option::Call);
    std::cout << "Option Type = " << OptionType << std::endl;
    
    return 0;
}

using the following command:

clang++ -std=c++11 ql_ex1.cpp -o build/ql_ex1 $(INC) $(LIB) \
    -I/opt/homebrew/Cellar/quantlib/1.23/include -I/opt/homebrew/Cellar/boost/1.76.0/include \
    -L/opt/homebrew/Cellar/boost/1.76.0/lib -L/opt/homebrew/Cellar/quantlib/1.23/lib

This gave me the following error message:

Undefined symbols for architecture arm64:
  "boost::assertion_failed(char const*, char const*, char const*, long)", referenced from:
      long double boost::math::detail::sinpx<long double>(long double) in ql_ex1-044d3e.o
  "boost::assertion_failed_msg(char const*, char const*, char const*, char const*, long)", referenced from:
      boost::array<long double, 171ul>::operator[](unsigned long) const in ql_ex1-044d3e.o
...
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1

So far I have tried the following approaches,

  • Install x86 binaries and run clang++ in emulation. I see the same Undefined symbols error.
  • Try to identify a Boost shared library file that I need to link to. I have not been able to find anything that contains the assertion_failed symbol.

Can someone point me to where (if anywhere) this symbol is defined? It would be useful to know if I am just missing the right compiler options or whether there is a more fundamental issue that needs to be addressed.

Aucun commentaire:

Enregistrer un commentaire