QuantLib installation on Mac OS X

Jack Harvard

Boost Installation

First, get MacPorts (http://www.macports.org/). Optionally, Porticus (http://porticus.alittledrop.com/) is a nice gui to use.

To install boost, run in Terminal:

sudo port install boost
Boost should install in /opt/local by default.

Alternatively, you can use Homebrew (http://brew.sh/). Homebrew installs in /usr/local instead.

QuantLib Installation

Download QuantLib from its download page on SourceForge, located at http://sourceforge.net/projects/quantlib/files/. You want to download the tar.gz package (at the time of this writing, 1.8 is the latest version) and extract it by running

tar xzvf QuantLib-1.8.tar.gz
in Terminal. To install QuantLib, enter the folder you just created:
cd QuantLib-1.8

On Mac OS X 10.9 (Mavericks) and later, you'll need to pass additional environment variables to ./configure (thanks to Albert Azout for pointing it out). Run:

./configure --with-boost-include=/opt/local/include/ \
            --with-boost-lib=/opt/local/lib/ --prefix=/opt/local/ \
            CXXFLAGS='-O2 -stdlib=libstdc++ -mmacosx-version-min=10.6' \
            LDFLAGS='-stdlib=libstdc++ -mmacosx-version-min=10.6'
(mind the backslash on the end of the lines; it tells the terminal to continue on the next line. You might also discard the backslash and write the whole command on a single line.) If your Boost installation is not in /opt/local, change the paths above accordingly.

On earlier systems, it's not necessary to pass environment variables, so the command can be simplified to:

./configure --with-boost-include=/opt/local/include/ \
            --with-boost-lib=/opt/local/lib/ --prefix=/opt/local/
Again, if your Boost installation is not in /opt/local, change the paths above accordingly.

Finally, run:

make && sudo make install
and then try to compile the examples. For example,
cd Examples/BermudanSwaption
g++ -I/opt/local/include/ -I/opt/local/include/boost BermudanSwaption.cpp \
    -o bermudanswaption -L/opt/local/lib/ -lQuantLib

The whole process can take a couple of hours if installing both Boost and QuantLib.

Appendix: Boost Configuration

If you want to make the Boost headers and libraries available to all C++ projects, edit ~/.bash_profile and add the following lines into the file:

export CPLUS_INCLUDE_PATH=/opt/local/include
export C_INCLUDE_PATH=/opt/local/include
export DYLD_LIBRARY_PATH=/opt/local/lib
When this is done, restart the terminal. After this, no include (-I) or link (-L) directory needs to be specified when compiling with g++.