Build A QuantLibAddin C++ Environment on Windows and/or Linux

Overview

This document provides general instructions for building a QuantLibAddin C++ environment under Windows, and on platforms which use Autoconf e.g. Linux.

1 Prerequisites
1.1 Conventions
1.2 Boost
1.3 Python 3.x
2 Windows
2.2 Download
2.3 Build
2.4 Test
2.5 Usage
3 Autoconf
3.2 Download
3.3 Build
3.4 Test
3.5 Usage

1 Prerequisites

Before proceeding to compile the source code, consult the documents below.

1.1 Conventions

See the following document regarding naming conventions in use for the project: Conventions

1.2 Boost

QuantLibAddin depends on Boost. Any recent version of Boost should be OK. The minimum version of Boost recommended for QuantLib is 1.48. You will need the compiled Boost libraries, the Boost header files alone are not sufficient.

1.3 Python 3.x

Some QuantLibAddin code is autogenerated by gensrc, which is a Python script. Before rebuilding QuantLibAddin you need to have Python 3.x installed on your machine. Here is the link to the Python website: http://www.python.org/.

On Windows, if Python is installed on your machine so that .py files are associated with the Python executable, then the gensrc scripts should build OK with no modification required.

Otherwise, after you install gensrc (below), you might need to edit these files...

    ObjectHandler\gensrc\Makefile.vc
    QuantLibAddin\gensrc\Makefile.vc

...and set the PYTHON variable equal to the location of the Python executable on your machine, e.g:

    PYTHON=C:\Users\username\AppData\Local\Programs\Python\Python39\python.exe

2 Windows

2.2 Download

2.2.1 Directories

The Visual C++ project files for QuantLibAddin rely on relative pathnames to refer to the prerequisite projects QuantLib, log4cxx, gensrc, and ObjectHandler. In order for this to work, these projects must reside side by side in the directory tree, and the name of each project's parent directory must not include the version number (e.g. QuantLib not QuantLib-1.22.0).

By default the installer for each project uncompresses the source code to C:\build_ql_1_22_0 (with the exception of the zip file for QuantLib, where you must manually specify the target directory, removing the 1.22.0 suffix from the directory name). For purposes of this tutorial we assume the packages have been installed in this way:

C:\build_ql_1_22_0\gensrc
C:\build_ql_1_22_0\log4cxx
C:\build_ql_1_22_0\ObjectHandler
C:\build_ql_1_22_0\QuantLib
C:\build_ql_1_22_0\QuantLibAddin

2.2.2 Uncompress the Source Code

Go to the QuantLib downloads page.

Download QuantLib-1.22.0.tgz and uncompress the package to C:\build_ql_1_22_0\QuantLib.

Go to the QuantLibAddin downloads page.

Download log4cxx-0.10.0f14.zip and uncompress the package to C:\build_ql_1_22_0\log4cxx.

Download gensrc-1.22.0.zip and uncompress the package to C:\build_ql_1_22_0\gensrc.

Download ObjectHandler-1.22.0.zip and uncompress the package to C:\build_ql_1_22_0\ObjectHandler.

Download QuantLib-1.22.0.zip and uncompress the package to C:\build_ql_1_22_0\QuantLib.

Download QuantLibAddin-1.22.0.zip and uncompress the package to C:\build_ql_1_22_0\QuantLibAddin.

2.3 Build

Open solution QuantLibAddin\QuantLibAddin_vc?.sln, choose configuration Release (static runtime), and execute menu item Build | Build Solution.

2.4 Test

Open a DOS prompt in directory

C:\build_ql_1_22_0\QuantLibAddin\Clients\Cpp\bin

Execute the example program. The output should appear similar to the following:

Begin example program.
QuantLibAddin version = 1.22.0
ObjectHandler version = 1.22.0
option PV = 3.84431
End example program.

2.5 Usage

2.5.1 #include

Add the following directive to your project's source file:

#include <qlo/qladdin.hpp>

2.5.2 Link

Your project's link to the QuantLibAddin library is established automatically by the directive

#pragma comment(lib, QLADDIN_LIB_NAME)

in file qlo/autolink.hpp

The name of the library depends on your compiler and configuration. For example, if you're using VC8, configuration Release (static runtime), the library is called

QuantLibAddin\lib\QuantLibObjects-vc80-mt-s-1.22.0.lib

3 Autoconf

3.2 Download

3.2.1 Directories

This example assumes that you do not have root access to your machine, so that the entire build and installation environment resides under your home directory.

Let's say your home directory is /home/erik. Create two subdirectories under that, one where you will compile the code and the other where you will install it:

/home/erik/build
/home/erik/install

3.2.2 Uncompress the Source Code

Go to the QuantLib downloads page.

Download QuantLib-1.22.0.tgz and uncompress the package to /home/erik/build/QuantLib-1.22.0.

Go to the QuantLibAddin downloads page.

Download log4cxx-0.10.0f14.tar.gz and uncompress the package to /home/erik/build/log4cxx-0.10.0.

Download gensrc-1.22.0.tgz and uncompress the package to /home/erik/build/gensrc-1.22.0.

Download ObjectHandler-1.22.0.tgz and uncompress the package to /home/erik/build/ObjectHandler-1.22.0.

Download QuantLibAddin-1.22.0.tgz and uncompress the package to /home/erik/build/QuantLibAddin-1.22.0.

3.3 Build

3.3.1 Build log4cxx

Support for log4cxx is optional. If you do not require logging, then when you configure ObjectHandler (see below), pass in the argument –without-log4cxx, which will cause log messages to be written to stdout instead of to the log file. In that case you can skip ahead to the next section, 3.3.2 Build ObjectHandler. If you need logging, read on.

First you need to install apr and apr-utils. Our copy of log4cxx includes source code for apr and apr-utils. In the past we used to build them with these commands:

cd /home/erik/build/log4cxx-0.10.0/src/apr
./buildconf
./configure --prefix=/home/erik/install
make install
cd /home/erik/build/log4cxx-0.10.0/src/apr-util
./buildconf
./configure --prefix=/home/erik/install --with-apr=/home/erik/install
make install

But those commands no longer seem to work on new linux systems. There might be a binary release available for your platform, on ubuntu you might try something like this:

sudo apt-get install libapr1-dev libaprutil1-dev

Another possibility is to go to the apache web site and download the latest sources for apr and apr-utils. At the time of this writing the files are apr-1.5.1.tar.gz and apr-util-1.5.3.tar.gz. Copy them to a temp directory, untar them, and compile them something like this:

cd /home/erik/temp/apr-1.5.1
./buildconf
./configure --prefix=/home/erik/install
make install
cd /home/erik/temp/apr-util-1.5.3
./buildconf --with-apr=../apr-1.5.1
./configure --prefix=/home/erik/install --with-apr=../apr-1.5.1
make install

Once you have apr and apr-utils installed, go back and build log4cxx:

cd /home/erik/build/log4cxx-0.10.0
./autogen.sh
./configure --prefix=/home/erik/install --with-apr=/home/erik/install \
    --with-apr-util=/home/erik/install
make install

3.3.2 Build ObjectHandler

If you don't need logging, pass in the argument –without-log4cxx to configure.

cd /home/erik/build/ObjectHandler-1.22.0
./configure --with-gensrc=/home/erik/build/gensrc-1.22.0 \
    --prefix=/home/erik/install \
    CPPFLAGS=-I/home/erik/install/include \
    LDFLAGS=-L/home/erik/install/lib
make install

3.3.3 Build QuantLib

cd /home/erik/build/QuantLib-1.22.0
./configure --prefix=/home/erik/install
make install

3.3.4 Build QuantLibAddin

cd /home/erik/build/QuantLibAddin-1.22.0
./configure --prefix=/home/erik/install --enable-addin-cpp \
    --with-gensrc=/home/erik/build/gensrc-1.22.0 \
    --with-oh=/home/erik/build/ObjectHandler-1.22.0 \
    CPPFLAGS=-I/home/erik/install/include \
    LDFLAGS=-L/home/erik/install/lib
make install

3.4 Test

cd /home/erik/build/QuantLibAddin-1.22.0/Clients/Cpp
./QLADemo

This should generate output similar to the following:

Begin example program.
QuantLibAddin version = 1.22.0
ObjectHandler version = 1.22.0
option PV = 3.84431
End example program.

3.5 Usage

To incorporate QuantLibAddin functionality into your own applications:

Suppose your application consists of source file yourapp.cpp:

#include <qlo/qladdin.hpp>
#include <iostream>

int main()
{
    std::cout << QuantLibAddin::qlAddinVersion() << std::endl;
}

To compile your program, ensure that the path containing the QuantLibAddin header is among those searched by your compiler. If you have followed the build instructions above, the command would be

g++ -I/home/erik/install/include -c -o yourapp.o yourapp.cpp

When linking your program use the -l option to tell gcc to link to the log4cxx, ObjectHandler, QuantLib, and QuantLibAddin libraries, and use -L to specify the path containing those libraries, e.g:

g++ -o yourapp yourapp.o -L/home/erik/install/lib \
    -llog4cxx -lObjectHandler -lQuantLib -lQuantLibAddin

Finally before invoking your executable you need to ensure that your loader knows where to find the libraries, e.g:

export LD_LIBRARY_PATH=/home/erik/install/lib