0
$\begingroup$

I wanted to run Quantlib with Visual Studio Code in Mac. I have successfully installed Quantlib in Mac as per the instructions in https://www.quantlib.org/install/macosx.shtml, which is working with Xcode.

However when I tried to run the below dummy code for Quantlib I failed to compile.

#include <iostream>
#include <iomanip>

#include <ql/option.hpp>

using namespace QuantLib;
 
int main() {
    
}

The error I was getting -

Undefined symbols for architecture x86_64:
  "boost::assertion_failed(char const*, char const*, char const*, long)", referenced from:
      boost::shared_ptr<QuantLib::Observable>::operator->() const in Try-731982.o
      boost::unordered::detail::table<boost::unordered::detail::set<std::__1::allocator<QuantLib::Observer*>, QuantLib::Observer*, boost::hash<QuantLib::Observer*>, std::__1::equal_to<QuantLib::Observer*> > >::get_bucket_pointer(unsigned long) const in Try-731982.o
      boost::shared_ptr<QuantLib::DayCounter::Impl>::operator->() const in Try-731982.o
      boost::shared_ptr<QuantLib::Calendar::Impl>::operator->() const in Try-731982.o
      boost::shared_ptr<QuantLib::IndexManager>::operator*() const in Try-731982.o
      boost::unordered::detail::functions<boost::hash<boost::shared_ptr<QuantLib::Observable> >, std::__1::equal_to<boost::shared_ptr<QuantLib::Observable> > >::~functions() in Try-731982.o
      boost::unordered::detail::table<boost::unordered::detail::set<std::__1::allocator<boost::shared_ptr<QuantLib::Observable> >, boost::shared_ptr<QuantLib::Observable>, boost::hash<boost::shared_ptr<QuantLib::Observable> >, std::__1::equal_to<boost::shared_ptr<QuantLib::Observable> > > >::get_bucket_pointer(unsigned long) const in Try-731982.o
      ...
  "QuantLib::Observable::notifyObservers()", referenced from:
      QuantLib::InterestRateIndex::update() in Try-731982.o
  "QuantLib::TermStructure::update()", referenced from:
      vtable for QuantLib::TermStructure in Try-731982.o
  "QuantLib::Date::Date()", referenced from:
      QuantLib::TermStructure::timeFromReference(QuantLib::Date const&) const in Try-731982.o
  "QuantLib::Error::Error(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, long, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)", referenced from:
      QuantLib::TermStructure::settlementDays() const in Try-731982.o
      QuantLib::InterestRateIndex::valueDate(QuantLib::Date const&) const in Try-731982.o
      QuantLib::InterestRateIndex::pastFixing(QuantLib::Date const&) const in Try-731982.o
      QuantLib::DayCounter::yearFraction(QuantLib::Date const&, QuantLib::Date const&, QuantLib::Date const&, QuantLib::Date const&) const in Try-731982.o
      QuantLib::Calendar::isBusinessDay(QuantLib::Date const&) const in Try-731982.o
  "QuantLib::Index::addFixing(QuantLib::Date const&, double, bool)", referenced from:
      vtable for QuantLib::InterestRateIndex in Try-731982.o
  "QuantLib::Coupon::accept(QuantLib::AcyclicVisitor&)", referenced from:
      vtable for QuantLib::Coupon in Try-731982.o
  "QuantLib::operator<<(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, QuantLib::Date const&)", referenced from:
      QuantLib::InterestRateIndex::valueDate(QuantLib::Date const&) const in Try-731982.o
      QuantLib::InterestRateIndex::pastFixing(QuantLib::Date const&) const in Try-731982.o
  "QuantLib::IndexManager::getHistory(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) const", referenced from:
      QuantLib::Index::timeSeries() const in Try-731982.o
  "QuantLib::TermStructure::referenceDate() const", referenced from:
      vtable for QuantLib::TermStructure in Try-731982.o
  "QuantLib::InterestRateIndex::fixing(QuantLib::Date const&, bool) const", referenced from:
      vtable for QuantLib::InterestRateIndex in Try-731982.o
  "QuantLib::Calendar::advance(QuantLib::Date const&, int, QuantLib::TimeUnit, QuantLib::BusinessDayConvention, bool) const", referenced from:
      QuantLib::InterestRateIndex::valueDate(QuantLib::Date const&) const in Try-731982.o
  "QuantLib::CashFlow::hasOccurred(QuantLib::Date const&, boost::optional<bool>) const", referenced from:
      vtable for QuantLib::Coupon in Try-731982.o
  "typeinfo for QuantLib::Error", referenced from:
      QuantLib::TermStructure::settlementDays() const in Try-731982.o
      QuantLib::InterestRateIndex::valueDate(QuantLib::Date const&) const in Try-731982.o
      QuantLib::InterestRateIndex::pastFixing(QuantLib::Date const&) const in Try-731982.o
      QuantLib::DayCounter::yearFraction(QuantLib::Date const&, QuantLib::Date const&, QuantLib::Date const&, QuantLib::Date const&) const in Try-731982.o
      QuantLib::Calendar::isBusinessDay(QuantLib::Date const&) const in Try-731982.o
  "typeinfo for QuantLib::Index", referenced from:
      typeinfo for QuantLib::InterestRateIndex in Try-731982.o
  "typeinfo for QuantLib::CashFlow", referenced from:
      typeinfo for QuantLib::Coupon in Try-731982.o
  "vtable for QuantLib::Error", referenced from:
      QuantLib::Error::~Error() in Try-731982.o
  NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
  "virtual thunk to QuantLib::TermStructure::update()", referenced from:
      vtable for QuantLib::TermStructure in Try-731982.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

[Done] exited with code=1 in 28.615 seconds

Any insight how to successfully run Quantlib C++ codes with Visual Studio Code in Mac will be very helpful.

Many thanks,

$\endgroup$
2
$\begingroup$

The code compiled, but it didn't link. You need to add /usr/local/lib/libQuantLib.dylib to the build (or .a, depending on how you compiled QuantLib—check which files you have in /usr/local/lib). I'm not familiar with VS Code, so I can't guide you step by step, but you can probably find instructions on how to add a library to a build.

$\endgroup$
1
  • $\begingroup$ That makes sense. Thanks for pointing out. $\endgroup$
    – Daniel
    Sep 2 '20 at 17:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.