QuantLib installation on Mac OS X

Jack Harvard

Boost Installation

The preferred way to get Boost is through Homebrew (http://brew.sh/). By default, Homebrew will install Boost in /usr/local. From Terminal, run:

brew install boost

Alternatively, you can use MacPorts (http://www.macports.org/) which installs in /opt/local instead.

QuantLib Installation

Installation from Homebrew

If you don't need to modify the library, you might want to skip the compilation and install a precompiled binary version. Unofficial binaries are available from Homebrew; run

  brew install quantlib

to install it. If you want to modify the library, instead, you'll have to compile it yourself as described in the next section.

Installation from a released version

Download QuantLib from its download page on Bintray, located at https://bintray.com/quantlib/releases/QuantLib. 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.11 (El Capitan) 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=/usr/local/include/ \
            --with-boost-lib=/usr/local/lib/ --prefix=/usr/local/ \
            CXXFLAGS='-O2 -stdlib=libc++ -mmacosx-version-min=10.9' \
            LDFLAGS='-stdlib=libc++ -mmacosx-version-min=10.9'
(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 /usr/local, change the paths above accordingly.

On Mac OS X 10.9 (Mavericks) and 10.10 (Yosemite), you'll need to pass different environment variables. Run:

./configure --with-boost-include=/usr/local/include/ \
            --with-boost-lib=/usr/local/lib/ --prefix=/usr/local/ \
            CXXFLAGS='-O2 -stdlib=libstdc++ -mmacosx-version-min=10.6' \
            LDFLAGS='-stdlib=libstdc++ -mmacosx-version-min=10.6'

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

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

Also, if you only intend to build the QuantLib Python module, you might want to pass the --disable-shared option to ./configure to only build a static library and avoid problems with dynamic loading.

Finally, run:

make
and
sudo make install
and then try to compile the examples. For example,
cd Examples/BermudanSwaption
g++ -I/usr/local/include/ -I/usr/local/include/boost BermudanSwaption.cpp \
    -o bermudanswaption -L/usr/local/lib/ -lQuantLib
Note that you might have to add more flags to the command above: some users report it working as is, while others report having to add the same -stdlib and -mmacosx-version-min used in the compilation of QuantLib. Also, if you installed QuantLib in some non-default prefix such as /opt/local, you might have to add corresponding include and library flags; in this case, they would be -I/opt/local/include and -L/opt/local/lib.

The whole process can take quite some time 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=/usr/local/include
export C_INCLUDE_PATH=/usr/local/include
export DYLD_LIBRARY_PATH=/usr/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++.