3
$\begingroup$

I have followed the guidlines for installing QuantLib for mac from here http://quantlib.org/install/macosx.shtml and also fixed the flags using the commands:

export CXXFLAGS = -stdlib=libstdc++

export LDFLAGS = -mmacosx-version-min=10.6

However, when I try to compile the examples as told in the guidlines, I get the following error:

In file included from BermudanSwaption.cpp:22:
In file included from /opt/local/include/ql/quantlib.hpp:43:
In file included from /opt/local/include/ql/experimental/all.hpp:25:
In file included from /opt/local/include/ql/experimental/volatility/all.hpp:21:
In file included from /opt/local/include/ql/experimental/volatility/zabr.hpp:31:
In file included from /opt/local/include/ql/math/statistics/incrementalstatistics.hpp:35:
In file included from /opt/local/include/boost/accumulators/statistics/stats.hpp:14:
In file included from /opt/local/include/boost/accumulators/statistics_fwd.hpp:12:
/opt/local/include/boost/mpl/print.hpp:50:19: warning: in-class initialization of non-static data member is a
      C++11 extension [-Wc++11-extensions]
    const int m_x = 1 / (sizeof(T) - sizeof(T));
                  ^
1 warning generated.
Undefined symbols for architecture x86_64:
  "QuantLib::MultiStepSwap::nextTimeStep(QuantLib::CurveState const&, std::__1::vector<unsigned long, std::__1::allocator<unsigned long> >&, std::__1::vector<std::__1::vector<QuantLib::MarketModelMultiProduct::CashFlow, std::__1::allocator<QuantLib::MarketModelMultiProduct::CashFlow> >, std::__1::allocator<std::__1::vector<QuantLib::MarketModelMultiProduct::CashFlow, std::__1::allocator<QuantLib::MarketModelMultiProduct::CashFlow> > > >&)", referenced from:
      vtable for QuantLib::MultiStepSwap in BermudanSwaption-a6bf28.o
  "QuantLib::ExerciseAdapter::nextTimeStep(QuantLib::CurveState const&, std::__1::vector<unsigned long, std::__1::allocator<unsigned long> >&, std::__1::vector<std::__1::vector<QuantLib::MarketModelMultiProduct::CashFlow, std::__1::allocator<QuantLib::MarketModelMultiProduct::CashFlow> >, std::__1::allocator<std::__1::vector<QuantLib::MarketModelMultiProduct::CashFlow, std::__1::allocator<QuantLib::MarketModelMultiProduct::CashFlow> > > >&)", referenced from:
      vtable for QuantLib::ExerciseAdapter in BermudanSwaption-a6bf28.o
  "QuantLib::OneStepForwards::nextTimeStep(QuantLib::CurveState const&, std::__1::vector<unsigned long, std::__1::allocator<unsigned long> >&, std::__1::vector<std::__1::vector<QuantLib::MarketModelMultiProduct::CashFlow, std::__1::allocator<QuantLib::MarketModelMultiProduct::CashFlow> >, std::__1::allocator<std::__1::vector<QuantLib::MarketModelMultiProduct::CashFlow, std::__1::allocator<QuantLib::MarketModelMultiProduct::CashFlow> > > >&)", referenced from:
      vtable for QuantLib::OneStepForwards in BermudanSwaption-a6bf28.o
  "QuantLib::BermudanExercise::BermudanExercise(std::__1::vector<QuantLib::Date, std::__1::allocator<QuantLib::Date> > const&, bool)", referenced from:
      _main in BermudanSwaption-a6bf28.o
  "QuantLib::MultiStepNothing::nextTimeStep(QuantLib::CurveState const&, std::__1::vector<unsigned long, std::__1::allocator<unsigned long> >&, std::__1::vector<std::__1::vector<QuantLib::MarketModelMultiProduct::CashFlow, std::__1::allocator<QuantLib::MarketModelMultiProduct::CashFlow> >, std::__1::allocator<std::__1::vector<QuantLib::MarketModelMultiProduct::CashFlow, std::__1::allocator<QuantLib::MarketModelMultiProduct::CashFlow> > > >&)", referenced from:
      vtable for QuantLib::MultiStepNothing in BermudanSwaption-a6bf28.o
  "QuantLib::MultiStepRatchet::nextTimeStep(QuantLib::CurveState const&, std::__1::vector<unsigned long, std::__1::allocator<unsigned long> >&, std::__1::vector<std::__1::vector<QuantLib::MarketModelMultiProduct::CashFlow, std::__1::allocator<QuantLib::MarketModelMultiProduct::CashFlow> >, std::__1::allocator<std::__1::vector<QuantLib::MarketModelMultiProduct::CashFlow, std::__1::allocator<QuantLib::MarketModelMultiProduct::CashFlow> > > >&)", referenced from:
      vtable for QuantLib::MultiStepRatchet in BermudanSwaption-a6bf28.o
  "QuantLib::MultiStepForwards::nextTimeStep(QuantLib::CurveState const&, std::__1::vector<unsigned long, std::__1::allocator<unsigned long> >&, std::__1::vector<std::__1::vector<QuantLib::MarketModelMultiProduct::CashFlow, std::__1::allocator<QuantLib::MarketModelMultiProduct::CashFlow> >, std::__1::allocator<std::__1::vector<QuantLib::MarketModelMultiProduct::CashFlow, std::__1::allocator<QuantLib::MarketModelMultiProduct::CashFlow> > > >&)", referenced from:
      vtable for QuantLib::MultiStepForwards in BermudanSwaption-a6bf28.o
  "QuantLib::MultiStepSwaption::nextTimeStep(QuantLib::CurveState const&, std::__1::vector<unsigned long, std::__1::allocator<unsigned long> >&, std::__1::vector<std::__1::vector<QuantLib::MarketModelMultiProduct::CashFlow, std::__1::allocator<QuantLib::MarketModelMultiProduct::CashFlow> >, std::__1::allocator<std::__1::vector<QuantLib::MarketModelMultiProduct::CashFlow, std::__1::allocator<QuantLib::MarketModelMultiProduct::CashFlow> > > >&)", referenced from:
      vtable for QuantLib::MultiStepSwaption in BermudanSwaption-a6bf28.o
  "QuantLib::OneStepOptionlets::nextTimeStep(QuantLib::CurveState const&, std::__1::vector<unsigned long, std::__1::allocator<unsigned long> >&, std::__1::vector<std::__1::vector<QuantLib::MarketModelMultiProduct::CashFlow, std::__1::allocator<QuantLib::MarketModelMultiProduct::CashFlow> >, std::__1::allocator<std::__1::vector<QuantLib::MarketModelMultiProduct::CashFlow, std::__1::allocator<QuantLib::MarketModelMultiProduct::CashFlow> > > >&)", referenced from:
      vtable for QuantLib::OneStepOptionlets in BermudanSwaption-a6bf28.o
  "QuantLib::MultiStepOptionlets::nextTimeStep(QuantLib::CurveState const&, std::__1::vector<unsigned long, std::__1::allocator<unsigned long> >&, std::__1::vector<std::__1::vector<QuantLib::MarketModelMultiProduct::CashFlow, std::__1::allocator<QuantLib::MarketModelMultiProduct::CashFlow> >, std::__1::allocator<std::__1::vector<QuantLib::MarketModelMultiProduct::CashFlow, std::__1::allocator<QuantLib::MarketModelMultiProduct::CashFlow> > > >&)", referenced from:
      vtable for QuantLib::MultiStepOptionlets in BermudanSwaption-a6bf28.o
  "QuantLib::OneStepCoinitialSwaps::nextTimeStep(QuantLib::CurveState const&, std::__1::vector<unsigned long, std::__1::allocator<unsigned long> >&, std::__1::vector<std::__1::vector<QuantLib::MarketModelMultiProduct::CashFlow, std::__1::allocator<QuantLib::MarketModelMultiProduct::CashFlow> >, std::__1::allocator<std::__1::vector<QuantLib::MarketModelMultiProduct::CashFlow, std::__1::allocator<QuantLib::MarketModelMultiProduct::CashFlow> > > >&)", referenced from:
      vtable for QuantLib::OneStepCoinitialSwaps in BermudanSwaption-a6bf28.o
  "QuantLib::OneStepCoterminalSwaps::nextTimeStep(QuantLib::CurveState const&, std::__1::vector<unsigned long, std::__1::allocator<unsigned long> >&, std::__1::vector<std::__1::vector<QuantLib::MarketModelMultiProduct::CashFlow, std::__1::allocator<QuantLib::MarketModelMultiProduct::CashFlow> >, std::__1::allocator<std::__1::vector<QuantLib::MarketModelMultiProduct::CashFlow, std::__1::allocator<QuantLib::MarketModelMultiProduct::CashFlow> > > >&)", referenced from:
      vtable for QuantLib::OneStepCoterminalSwaps in BermudanSwaption-a6bf28.o
  "QuantLib::MultiStepCoinitialSwaps::nextTimeStep(QuantLib::CurveState const&, std::__1::vector<unsigned long, std::__1::allocator<unsigned long> >&, std::__1::vector<std::__1::vector<QuantLib::MarketModelMultiProduct::CashFlow, std::__1::allocator<QuantLib::MarketModelMultiProduct::CashFlow> >, std::__1::allocator<std::__1::vector<QuantLib::MarketModelMultiProduct::CashFlow, std::__1::allocator<QuantLib::MarketModelMultiProduct::CashFlow> > > >&)", referenced from:
      vtable for QuantLib::MultiStepCoinitialSwaps in BermudanSwaption-a6bf28.o
  "QuantLib::MultiStepInverseFloater::nextTimeStep(QuantLib::CurveState const&, std::__1::vector<unsigned long, std::__1::allocator<unsigned long> >&, std::__1::vector<std::__1::vector<QuantLib::MarketModelMultiProduct::CashFlow, std::__1::allocator<QuantLib::MarketModelMultiProduct::CashFlow> >, std::__1::allocator<std::__1::vector<QuantLib::MarketModelMultiProduct::CashFlow, std::__1::allocator<QuantLib::MarketModelMultiProduct::CashFlow> > > >&)", referenced from:
      vtable for QuantLib::MultiStepInverseFloater in BermudanSwaption-a6bf28.o
  "QuantLib::MultiStepCoterminalSwaps::nextTimeStep(QuantLib::CurveState const&, std::__1::vector<unsigned long, std::__1::allocator<unsigned long> >&, std::__1::vector<std::__1::vector<QuantLib::MarketModelMultiProduct::CashFlow, std::__1::allocator<QuantLib::MarketModelMultiProduct::CashFlow> >, std::__1::allocator<std::__1::vector<QuantLib::MarketModelMultiProduct::CashFlow, std::__1::allocator<QuantLib::MarketModelMultiProduct::CashFlow> > > >&)", referenced from:
      vtable for QuantLib::MultiStepCoterminalSwaps in BermudanSwaption-a6bf28.o
  "QuantLib::MultiStepCoterminalSwaptions::nextTimeStep(QuantLib::CurveState const&, std::__1::vector<unsigned long, std::__1::allocator<unsigned long> >&, std::__1::vector<std::__1::vector<QuantLib::MarketModelMultiProduct::CashFlow, std::__1::allocator<QuantLib::MarketModelMultiProduct::CashFlow> >, std::__1::allocator<std::__1::vector<QuantLib::MarketModelMultiProduct::CashFlow, std::__1::allocator<QuantLib::MarketModelMultiProduct::CashFlow> > > >&)", referenced from:
      vtable for QuantLib::MultiStepCoterminalSwaptions in BermudanSwaption-a6bf28.o
  "QuantLib::MultiStepPeriodCapletSwaptions::nextTimeStep(QuantLib::CurveState const&, std::__1::vector<unsigned long, std::__1::allocator<unsigned long> >&, std::__1::vector<std::__1::vector<QuantLib::MarketModelMultiProduct::CashFlow, std::__1::allocator<QuantLib::MarketModelMultiProduct::CashFlow> >, std::__1::allocator<std::__1::vector<QuantLib::MarketModelMultiProduct::CashFlow, std::__1::allocator<QuantLib::MarketModelMultiProduct::CashFlow> > > >&)", referenced from:
      vtable for QuantLib::MultiStepPeriodCapletSwaptions in BermudanSwaption-a6bf28.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::DiscretizedOption::reset(unsigned long) in BermudanSwaption-a6bf28.o
      QuantLib::Instrument::setupArguments(QuantLib::PricingEngine::arguments*) const in BermudanSwaption-a6bf28.o
      QuantLib::Option::setupArguments(QuantLib::PricingEngine::arguments*) const in BermudanSwaption-a6bf28.o
      QuantLib::Payoff::accept(QuantLib::AcyclicVisitor&) in BermudanSwaption-a6bf28.o
      QuantLib::BlackVolTermStructure::accept(QuantLib::AcyclicVisitor&) in BermudanSwaption-a6bf28.o
      QuantLib::SimpleQuote::value() const in BermudanSwaption-a6bf28.o
      QuantLib::Handle<QuantLib::Quote>::operator->() const in BermudanSwaption-a6bf28.o
      ...
  "QuantLib::detail::operator<<(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, QuantLib::detail::percent_holder const&)", referenced from:
      calibrateModel(boost::shared_ptr<QuantLib::ShortRateModel> const&, std::__1::vector<boost::shared_ptr<QuantLib::CalibrationHelper>, std::__1::allocator<boost::shared_ptr<QuantLib::CalibrationHelper> > > const&) in BermudanSwaption-a6bf28.o
      _main in BermudanSwaption-a6bf28.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 BermudanSwaption-a6bf28.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Is there something wrong I have done? What is the problem with the "linker" here? I would really appreciate for help since I have been trying to get this to work for a very long time now.

$\endgroup$

3 Answers 3

2
$\begingroup$

You can't just compile BermudanSwaption.cpp and hope everything would be fine. You have to compile the entire QuantLib library and link with the generated library files. Please google "compiling and linking C++" for more information.

By far, the easiest way to make it happen on Mac is to do it with Xcode. You will need to create a new Xcode project, and import the entire Quantlib project files into it. Next, you will need to create a main() function. Xcode does the compiling and linking for your automatically.

In my screenshot, I have QuantLib working in Xcode and was trying the OU process.

enter image description here

$\endgroup$
2
  • $\begingroup$ Did exactly as you did, however #include <ql/quantlib.hpp> is not found according to XCode, even if i can see it there $\endgroup$
    – Elekko
    Commented Feb 26, 2016 at 2:12
  • 1
    $\begingroup$ @Elekko You need to add an INCLUDE path to Xcode for where you install the files. $\endgroup$
    – SmallChess
    Commented Feb 26, 2016 at 3:07
1
$\begingroup$

I've also met such an question several mins before and I realized that this error cause from the standard library set by Mac. One should set -stdlib=libstdc++ when building, compared to the libc++ by default on several recent MAC versions.

$\endgroup$
1
  • $\begingroup$ why is this the case - my install errors say to use libc++ (which is the newer one, on mac os x 10.12) $\endgroup$
    – rrg
    Commented Apr 8, 2017 at 17:01
1
$\begingroup$

@SmallChess mostly covered it here.

You cannot expect Unix to know what QuantLib is and where it is if you enter -l QuantLib... QuantLib is written in C++ and the library itself has to be compiled locally (i.e., you have to do it yourself!).

On Xcode you need to got to the C/C++ build configuration settings, and add it as a library. I would think you would just enter "QuantLib" but it depends. You may have to go to /usr/include/, /usr/bin/, /usr/local/, etc. to see where it is and what it's named. You may also have to provide the entire path. You also need to link boost in Xcode, because it utilities functions from both libraries.

You can also do something like

echo $CXX 

And then

echo $CXXFLAGS

And this will tell you the value of the flags you're using. However I disagree with "By far, the easiest way to make it happen on Mac is to do it with Xcode", do it wherever you want, Xcode, Vim, whatever just make sure you tell Clang where the libraries are!

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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