QuantLib installation in VC++

Based on the initial instructions by Dominik Holenstein and Dimitri Reiswich

These are step-by-step instructions to install QuantLib and Boost on the Microsoft Visual C++ IDE. These instructions work on recent versions (you can download the latest free Community edition on the Microsoft web site), but unfortunately the screenshots on this page were taken a long time ago on Visual C++ 2010. If you want to contribute updated versions, that would be great.

Before using QuantLib, you need to install the Boost library on your computer. Detailed instructions follow in the next section.

Boost Installation

We use the binary installer provided by the Boost project, that can be downloaded from their Artifactory.

You'll have to enter the folder corresponding to the release you want to download (we suggest to choose the latest version), then the binaries folder, and then choose the installer corresponding to your compiler and platform; for instance, boost_1_81_0-msvc-14.3-64.exe for Visual C++ 2022 on a 64-bit system. Download and run the installer. Again, the figures in this tutorial were produced a while ago and assumed that you installed Boost 1.47 into the C:\Program Files\Boost\boost_1_47 folder; replace that with whatever folder the installer creates for your newer version (for instance, C:\local\boost_1_81_0).

Boost and QuantLib Installation

Here are the steps to make the installed Boost libraries available to QuantLib:

1. Open Visual Studio and make sure you have activated the expert settings. Go to Tools/Settings and make sure "Expert Settings" is checked. This might not be necessary in recent versions.

2. If you haven't downloaded QuantLib yet, go to its release page on GitHub.

3. Find the latest version and download the zip archive to your local drive. Unzip the file wherever you want; in the following, we'll assume that the QuantLib directory is C:\Program Files\QuantLib.

4. Open the QuantLib folder, then open the Visual Studio solution called QuantLib.sln by double clicking it. Choose Release from the configuration menu in the toolbar.

5. Open the Property Manager by clicking on View/Property Manager (or View/Other Windows/Property Manager, depending on your version of Visual Studio) and activate it. Expand the project node of QuantLib in the Property Manager and then the Configuration/Platform nodes (see screenshot below).

Earlier Visual C++ versions used Microsoft.cpp.<Platform>.users files for global settings. However, these files are now deprecated and, depending on your Visual C++ version, might no longer be available. If that is the case, or if you want to follow Microsoft's advice anyway, create a new property page as described at this link, add it to all projects in the solution, and use that instead of the .users files.

Select any of the new or global pages (or multi-select them all), right-click, and select Properties to bring up the property page window.

Property
Pages

6. In the property page window, click on VC++ Directories on the left pane and add the paths for the Boost directories in Include Directories and Library Directories in the right pane. If you installed Boost in C:\local\boost_1_81_0, you'll have to add that to the include directories. Instead, the folder to add to the library directories has a name such as C:\local\boost_1_01_0\lib32-msvc-12.0 or C:\local\boost_1_81_0\lib64-msvc-14.3 which includes compiler and build information; if you installed multiple ones, choose the one corresponding to your configuration. Click the OK button to set your changes.

Directories
Dialog

7. Switch back to the Solutions Explorer, right-click on the solution icon and choose Build Solution to build all projects. Besides QuantLib, this will build the examples and run the test suite. The process takes a while (it took 1h and 7 minutes to build QuantLib and run the tests on a three-years old WinXP notebook with 3 GB RAM and a 2 GHz Intel dual core processor).

Build
Solution

After finishing, the output should show no errors (and hopefully, a shorter run time):

14>  Test suite "Master Test Suite" passed with:
14>    1703 assertions out of 1703 passed
14>    460 test cases out of 460 passed
14>  
14>   
14>  Tests completed in 29 m 8 s
14>  
========== Build: 15 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========

You are done with building QuantLib. If you want, you can build the Debug version in the same way by choosing Debug from the configuration menu as shown below. This will allow you to debug your application later.

Debug
Configuration

Quantlib Usage

As an example of QuantLib usage, I create a QuantLibTest folder in the C:\Program Files\QuantLib folder and set up a Win32 Console Application in Visual Studio by clicking File/New Project/Win32 Console Application.

New Project

I've chosen the project name TestingQuantLib, then I clicked on OK. Click on the Next button on the Win32 Application Wizard. Choose "Console application" as application type and check "Empty project" in the additional options. Click on Finish.

Application
Wizard

Choose, for example, the Release mode for that project. Note that very often, users don't setup a project correctly since they build QuantLib in one mode and try to call it from a test program which runs in some other mode. If you built QuantLib in release mode, you should build your project in release mode. If you build your project in debug mode without ever building QuantLib in debug mode, you'll have link errors.

To tell your project where to find QuantLib, open the project properties by right-clicking on the project icon in the IDE.

Open Project
Properties

Go to VC++ Directories. You can see that the Boost folders are already there, so you don't have to do anything to configure them.

Project
Properties

Add the QuantLib path (C:\Program Files\QuantLib in this example) to the include directories. The result should be as shown below.

QuantLib include directory

Finally, you can add the QuantLib library path C:\Program Files\QuantLib\lib to the library directories, or you can go to Configuration Properties/Linker/General and add it to Additional Library Directories. Click OK.

QuantLib library dir

To test if the setup works, add the following program to the TestingQuantLib project. The program tests some Date and Calendar classes.

#include <ql/quantlib.hpp>
#include <iostream>

int main()
{
        QuantLib::Calendar myCal=QuantLib::UnitedKingdom();
        QuantLib::Date newYearsEve(31,QuantLib::Dec,2008);

        std::cout << "Name: "                       << myCal.name()<< std::endl;
        std::cout << "New Year is Holiday: "        << myCal.isHoliday(newYearsEve)<< std::endl;
        std::cout << "New Year is Business Day: "   << myCal.isBusinessDay(newYearsEve)<< std::endl;

        std::cout << "--------------- Date Counter --------------------" << std::endl;

        QuantLib::Date date1(28,QuantLib::Dec,2008);
        QuantLib::Date date2(04,QuantLib::Jan,2009);

        std::cout << "First Date: "            << date1 << std::endl;
        std::cout << "Second Date: "           << date2 << std::endl;
        std::cout << "Business Days Betweeen: "<< myCal.businessDaysBetween(date1,date2) << std::endl;
        std::cout << "End of Month 1. Date: "  << myCal.endOfMonth(date1) << std::endl;
        std::cout << "End of Month 2. Date: "  << myCal.endOfMonth(date2) << std::endl;

        double tmp;
        std::cin >> tmp;

        return 0;
}

Hit F5 to run the program. The output of the program should be:

Program output

One last thing: If you see some warnings after building, to get rid of them open the project properties again, go to Configuration Properties/C/C++/Preprocessor/Preprocessor Definitions and add _SCL_SECURE_NO_DEPRECATE and _CRT_SECURE_NO_DEPRECATE to the definitions, as shown here:

Preprocessor defs

Now, building the TestingQuantLib project again shouldn't show you any warnings anymore, just as in the Output window below.

Test output

We're done!