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
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.gzin 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:
makeand
sudo make installand 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/ -lQuantLibNote 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/libWhen this is done, restart the terminal. After this, no include (-I) or link (-L) directory needs to be specified when compiling with g++.