Quantitative Development Compiling QuantLib in Debug Mode and wiring com...

Compiling QuantLib in Debug Mode and wiring components into SWIG - Python.

Compiling QuantLib in Debug Mode and wiring components into SWIG - Python.

When experimenting with pricing engines, term structures, or custom instruments in QuantLib, I usually want more than a fast binary. I want debuggability. That means line information, symbols, and a build that lets me inspect internal state step by step, both from C++ and from the Python wrapper.

This post captures my preferred setup to compile QuantLib in Debug mode and then connect that build to QuantLib-SWIG so selected components can be consumed from Python.

QuantLib Main Layers

Before diving into compilation stages, it helps to keep QuantLib architecture in mind. The engine core is implemented in C++, for instance instruments, term structures, pricing engines, calendars, and numerical methods live there. On top of that, QuantLib-SWIG, provides the language binding layer that maps selected C++ classes and methods into Python-accessible objects. Other programming languages are also supported, such as Java, R, Scala and C#.

SWIG (Simplified Wrapper and Interface Generator) is a tool that reads interface definitions and generates the glue code required for high-level languages to call C/C++ code. In practice for QuantLib, it acts as a translator between C++ types and Python objects in our example. That is why users can often install and consume QuantLib from Python with pip, while still relying on the C++ core under the hood. Below a brief plog showing the flow of code construction and communication.

flowchart RL
  U[Quant Validator/Developer/Analyst]

  subgraph PyLayer[Python Layer]
    P1[Research notebooks]
    P2[Trading and risk scripts]
    P3[pip package QuantLib]
  end

  subgraph BindLayer["Binding Layer (SWIG)"]
    S1[SWIG interface files .i]
    S2[Generated wrapper code]
    S3[Python extension module]
  end

  subgraph CoreLayer["QuantLib (C++ Core)"]
    C1[Instruments and cashflows]
    C2[Term structures and models]
    C3[Pricing engines and solvers]
    C4["Shared Library (_Quantlib.*.so)"]
  end

  P1 --> U
  P2 --> U
  P3 --> S3
  P3 --> P1
  P3 --> P2

  S3 --> P3
  S1 --> S2 --> S3

  C1 --> C4
  C2 --> C4
  C3 --> C4
  C4 --> S3

  classDef user fill:#2d1e46,stroke:#c8a8ff,stroke-width:2px,color:#f5ecff;
  classDef py fill:#12324a,stroke:#8fd3ff,stroke-width:2px,color:#eaf7ff;
  classDef bind fill:#2b3a1b,stroke:#aeea86,stroke-width:2px,color:#f2ffe8;
  classDef core fill:#4a2a18,stroke:#ffbe8b,stroke-width:2px,color:#fff2e8;
  classDef core_lib fill:#F54927,stroke:#F52800,stroke-width:2px,color:#fff2e8;

  class U user;
  class P1,P2,P3 py;
  class S1,S2,S3 bind;
  class C1,C2,C3 core;
  class C4 core_lib;

The most important idea in this diagram is the round-trip loop: Python code calls into wrapped interfaces, those interfaces execute C++ QuantLib logic, and results come back to Python for analysis and orchestration. Performance-critical logic stays in C++, while productivity and experimentation remain in Python.

The Evidence

Checking this architecture seems to be easy in Python layer, reason why I would suggest to you to install QuantLib in python, for instance using pip, as shown below.

pip install QuantLib

Then start a python instance and type the following lines.

>>> import QuantLib as ql
>>> ql.__file__

This displays the location of the root module in your machine, like /.../python3.13/site-packages/QuantLib/QuantLib.py. You can remove /QuantLib.py from the string and you’ll get the path folder where the library is installed. Thus, the purpose is to check the content of the library just installed. You’ll see a directory tree like this below.

├── __init__.py
├── __pycache__
│   ├── __init__.cpython-313.pyc
│   └── QuantLib.cpython-313.pyc
├── _QuantLib.abi3.so
└── QuantLib.py

The shared library _QuantLib.abi3.so can be easily identified, together with the file that supports the pythonic definitions, for those objects available in the shared library. But don’t worry if you are curious and you see the very large QuantLib.py file. Fortunately, that’s the type of files SWIG helps to built by means the *.i interface files.

Hope this has convinced you of the architecture from the Python perspective, then lets start the journey from the core.

C++ Core

Unlike the previous post installing QuantLib, this occasion the post is focused on debugging the library. Thereby, before jumping into the setup details, it is useful to visualize what really happens when C++ code is compiled. The pipeline is deterministic:

  1. the preprocessor expands directives and headers,
  2. the compiler translates units into assembly,
  3. the assembler emits object files, and
  4. the linker resolves symbols across objects and libraries to produce the final binary.
flowchart TB
  subgraph Inputs[Source Inputs]
    S1[main.cpp]
    S2[pricing_engine.cpp]
    H1[quantlib headers .hpp]
    H2[project headers .hpp]
  end

  subgraph PP[1. Preprocessor]
    P1[Expand #include]
    P2[Expand #define]
    P3[Conditional blocks #if #ifdef]
    TU["Preprocessed translation units (.ii)"]
  end

  subgraph C[2. Compiler]
    C1[Parse and type-check]
    C2[Template instantiation]
    C3[Optimization level O0 in Debug]
    ASM["Assembly files (.s)"]
  end

  subgraph A[3. Assembler]
    A1[Encode instructions]
    A2[Generate relocation entries]
    OBJ["Object files (.o)"]
  end

  subgraph L[4. Linker]
    L1[Resolve external symbols]
    L2[Merge sections text data bss]
    L3[Bind shared libs and static libs]
    OUT["Executable or shared library (.so or .dll)"]
  end

  subgraph DebugArtifacts[Debug Artifacts]
    D1[DWARF debug info -g]
    D2[Line mapping source to machine code]
    D3[Symbol tables for gdb lldb]
  end

  S1 --> P1
  S2 --> P1
  H1 --> P1
  H2 --> P1

  P1 --> P2 --> P3 --> TU
  TU --> C1 --> C2 --> C3 --> ASM
  ASM --> A1 --> A2 --> OBJ
  OBJ --> L1 --> L2 --> L3 --> OUT

  D1 --> L
  D2 --> L
  D3 --> L

  classDef inputs fill:#1f2a44,stroke:#8fb8ff,stroke-width:2px,color:#eef4ff;
  classDef stage fill:#20331e,stroke:#9ee38f,stroke-width:2px,color:#ecffe7;
  classDef artifact fill:#3a2415,stroke:#ffc081,stroke-width:2px,color:#fff1e2;
  classDef debug fill:#3a1e35,stroke:#ff9fd8,stroke-width:2px,color:#ffeefe;

  class S1,S2,H1,H2 inputs;
  class P1,P2,P3,C1,C2,C3,A1,A2,L1,L2,L3 stage;
  class TU,ASM,OBJ,OUT artifact;
  class D1,D2,D3 debug;

The key practical idea is this: when you compile with debug flags, the final artifact is not only machine code. It also carries metadata that maps execution back to your source files, so breakpoints, stack traces, and variable inspection become meaningful.

Why Debug mode for QuantLib?

Release builds are great for benchmarks and production since they’re lean and fast. But when you’re in the thick of R&D (Research and Development), they’re like debugging with one eye closed. A debug build, on the other hand, gives you full visibility into what’s happening under the hood.

Imagine you’re building a custom pricing model and something is not behaving as expected. With debug symbols in place, you can step through your code, watch object lifetimes unfold, and inspect intermediate values as they flow through your pricing paths. You can validate your assumptions about how your custom extensions interact with QuantLib’s internals, catch logic bugs before they cascade into production, and verify that your SWIG bindings are actually exporting what you think they are.

Yes, debug builds are slower. But that transparency is worth every millisecond when you’re trying to understand what went wrong, or worse, when you’re not even sure if something is wrong yet.

1. Build QuantLib in Debug mode

The first step is compiling and installing a debug copy of QuantLib into a dedicated folder. Keeping a separate prefix avoids collisions with your existing release install. First create a folder in an accessible folder within your computer. Avoid creating it within paths in Cloud folders like OneDrive, GoogleSites. This example will use the folder /quantlib-debug-install located at $HOME level in Linux. Similar analogy can be applied in Windows win C:/users/<your-user>. Then the commands below can be executed.

# 1) Clone (or reuse) QuantLib source
cd $HOME/GIT
git clone https://github.com/lballabio/QuantLib.git
cd QuantLib

# 2) Configure a debug build directory
cmake -S . -B build \
  -DCMAKE_BUILD_TYPE=Debug \
  -DBUILD_SHARED_LIBS=ON \
  -DCMAKE_INSTALL_PREFIX=$HOME/quantlib-debug-install

# 2) [Alternative] Configure a debug build directory when Boost is in your VCPKG package manager
cmake -S . -B build
  -DCMAKE_BUILD_TYPE=Debug
  -DCMAKE_TOOLCHAIN_FILE=/<path-to-vcpkg>/vcpkg/scripts/buildsystems/vcpkg.cmake
  -DCMAKE_CXX_FLAGS_DEBUG="-g -save-temps=obj"
  -DCMAKE_INSTALL_PREFIX=$HOME/quantlib-debug-install

# 3) Compile
cmake --build build -j$(nproc)

# 4) Install
cmake --install build

Commands Explanation

Below the step by step description of commans above.

Step 1. Clone (or reuse) QuantLib source

This step retrieves the full QuantLib source tree from the official repository and places your terminal inside the project root. Practically, this gives you access to the top-level CMakeLists.txt and all C++ sources that will be configured and compiled in the next steps. If you already have a local clone, you can reuse it and only update it as needed.

Step 2. Configure the build directory

This step does not compile anything yet. Instead, it prepares the build system files inside the build folder. The parameter -DCMAKE_BUILD_TYPE=Debug enables debug-oriented compilation flags, -DBUILD_SHARED_LIBS=ON requests shared library generation, and -DCMAKE_INSTALL_PREFIX=... defines where headers and libraries will be installed. In the VCPKG alternative, -DCMAKE_TOOLCHAIN_FILE tells CMake where to resolve dependencies from VCPKG (i.e., Boost), and -DCMAKE_CXX_FLAGS_DEBUG="-g -save-temps=obj" keeps debug symbols and intermediate artifacts for inspection.

To check any flag and/or variable used during compilation/installation, such as CMAKE_INSTALL_PREFIX, you can check its value in /build/CMakeCache.txt file. This file is created once the command is run. The value of this variable must coincide with the folder we have created for debuging purpose, namely, CMAKE_INSTALL_PREFIX:PATH=/<path-to-your-home>/quantlib-debug-install.

Step 3. Compile

This step runs the actual compilation process by invoking the generator configured in the previous step (for example Makefiles or Ninja). cmake --build build compiles QuantLib targets, while -j$(nproc) uses all available CPU cores to reduce total build time. At this stage you should expect object files, dependency files, and the resulting QuantLib shared library to be produced under the build tree.

It is the most time consuming step, as it will compile all the C++ codes leveraged in parallel processes. In this case, used as a reference, the compilation took 15 minutes. This stage creates all the artifacts by c++ file, listed in below in Generated Artifacts. At this stage, all the artifacts are stored in /build folder, but not installed yet.

Step 4. Install

This step copies the build outputs from the build tree into the installation prefix defined earlier. In practice, headers go to include, libraries go to lib, and any additional artifacts are placed in their corresponding install folders. Using sudo may be required depending on target path permissions, but if your prefix is under $HOME you can usually install without elevated privileges.

At this stage, three folders should have been created within /quantlib-debug-install folder. They are described below.

Folder What it contains Why it matters
bin Executable helper tools installed by the project/build system (if any are generated for your platform/configuration). Useful when QuantLib or related tooling exposes command-line utilities. This includes the exposure to SWIG interfaces compilation.
include Public header files, mainly under include/ql/..., used by external C++ projects at compile time. Required to compile your own C++ code that includes QuantLib headers.
lib Compiled libraries such as libQuantLib.so (or platform equivalent), plus related library metadata/symlinks. Required at link and runtime so your applications can call QuantLib implementations. This will contain the debug symbols.

Execute to validate quickly:

ls $HOME/quantlib-debug-install
ls $HOME/quantlib-debug-install/lib

Copying Binaries

On Unix-like operating systems, you need to copy the binaries generated in /quantlib-debug-install/bin folder to the system folder /usr/local/lib. This step is critical because it allows the system and build tools to properly locate and link against the QuantLib libraries. More importantly, this enables QuantLib-SWIG to successfully compile the Python library, as the SWIG build process needs to resolve the QuantLib dependencies during the Python extension module generation.

To copy the libraries and binaries:

sudo cp -r $HOME/quantlib-debug-install/bin/* /usr/local/bin/
sudo cp -r $HOME/quantlib-debug-install/include/* /usr/local/include/
sudo ldconfig  # Update the system's library cache

This ensures that when QuantLib-SWIG attempts to build the Python bindings, it can find the necessary .so files and headers without additional configuration, allowing the Python extension modules to compile and link correctly.

Generated Artifacts

The installation creates intermediate files in \build folder, like those ones with extension .ii, .o, .s, and .o.d, as described in Step 3. Each file has a purpose, as described in table below.

File extension Build stage Purpose
.ii Preprocessing Preprocessed C++ source after expanding #include, macros, and conditional directives. Useful to inspect what the compiler really receives.
.s Compilation Assembly output generated by the compiler from the translation unit. Useful to inspect low-level code generation.
.o Assembling Object file containing machine code and symbol/relocation info for one translation unit, later consumed by the linker.
.o.d Dependency generation Make-style dependency file listing headers used by the source file, so incremental builds know what must be rebuilt when headers change.

Back to Step 3. Compile.

install_manifest.txt and a proper uninstall

After running cmake --install build, CMake writes a file named install_manifest.txt inside your build directory (for example build/install_manifest.txt). This file contains one installed path per line and acts as the authoritative list of what the install step copied into your system or install prefix.

Because CMake does not create a universal cmake --uninstall command by default, the safest uninstall approach (If required) is to use this manifest as input. Always preview first, then remove, not both at same time.

# 1. Preview what will be removed:
sudo xargs -a /build/install_manifest.txt -I{} echo rm -v "{}"

# 2. Remove installed files:
sudo xargs -a /build/install_manifest.txt rm -v

Run these commands from the same build folder where install_manifest.txt exists, or provide the full path to the manifest file.

3. SWIG and QuantLib-SWIG

Now comes the Python bridge. Before diving into the build, it’s important to understand what SWIG does and why it’s essential for QuantLib’s Python ecosystem. Now comes the Python bridge. Before diving into the build, it’s important to understand what SWIG does and why it’s essential for QuantLib’s Python ecosystem.

What is SWIG?

SWIG (Simplified Wrapper and Interface Generator) is a tool that automatically generates language bindings for C++ libraries. QuantLib is a large, mature C++ library with hundreds of classes, enums, and functions. Writing Python bindings manually would be impractical and error-prone. SWIG solves this by:

  • Reading C++ headers and interface files (.i or .hpp) that describe the library’s API
  • Generating wrapper code that translates Python function calls into C++ calls
  • Creating compiled extension modules (.so files on Linux) that Python can import
  • Handling type conversions between Python and C++ (e.g., Python floats to C++ doubles)

Why SWIG for QuantLib?

QuantLib’s Python module (accessible via import QuantLib) is entirely built by SWIG. Without it we could only use QuantLib from C++ applications, therefore there would be no QuantLib.EuropeanOption, QuantLib.BlackScholesProcess, or other Python classes.

SWIG bridges the 20-year investment in C++ financial models into the Python ecosystem, allowing quants to prototype and backtest strategies in Python while leveraging a battle-tested C++ engine. Below a brief summary of the process followed to create the Python wheel, eventually installed via PIP.

flowchart TB
  subgraph QLCore[QuantLib C++ Debug Install]
    QH[Headers include/ql/*.hpp]
    QL[Library lib/libQuantLib.so]
    QCfg[quantlib-config in bin/]
  end

  subgraph SWIGSpec[QuantLib-SWIG Interface Layer]
    IRoot[SWIG/*.i root modules]
    IComp[Component *.i includes]
    IGlue[Typemaps and glue directives]
  end

  subgraph BuildSteps[Wrapper Build Pipeline]
    Cfg[./configure in Python/]
    SWIGRun[swig reads .i and C++ headers]
    WrapCpp[Generated C++ wrapper source\nQuantLib_wrap.cpp]
    Compile[Compile wrapper C++]
    Link[Link extension against libQuantLib.so]
  end

  subgraph PyArtifacts[Python Package Artifacts]
    Ext[_QuantLib*.so extension module]
    PyFile[QuantLib.py high-level API]
    Init[__init__.py package entry]
    Meta[dist-info metadata\nMETADATA WHEEL RECORD]
  end

  subgraph WheelOut[Wheel Output]
    Whl[QuantLib-<ver>-*.whl]
  end

  IRoot --> IComp --> IGlue
  IGlue --> SWIGRun
  QH --> SWIGRun
  QCfg --> Cfg --> SWIGRun
  SWIGRun --> WrapCpp --> Compile --> Link
  QL --> Link
  Link --> Ext
  SWIGRun --> PyFile
  Ext --> Whl
  PyFile --> Whl
  Init --> Whl
  Meta --> Whl

  classDef core fill:#1f2a44,stroke:#8fb8ff,stroke-width:2px,color:#eef4ff;
  classDef iface fill:#25351f,stroke:#9ee38f,stroke-width:2px,color:#ecffe7;
  classDef build fill:#3f2d1c,stroke:#ffc081,stroke-width:2px,color:#fff1e2;
  classDef py fill:#2f1f3d,stroke:#d8a8ff,stroke-width:2px,color:#f7edff;
  classDef out fill:#4a1f1f,stroke:#ff9b9b,stroke-width:2px,color:#fff0f0;

  class QH,QL,QCfg core;
  class IRoot,IComp,IGlue iface;
  class Cfg,SWIGRun,WrapCpp,Compile,Link build;
  class Ext,PyFile,Init,Meta py;
  class Whl out;

📌 What are .i files?

SWIG interface files (.i files) are text files that specify which C++ classes, functions, and types should be exposed to Python. They act as a “contract” between C++ and Python:

  • They tell SWIG what to wrap (not everything in the C++ library is wrapped)
  • They define how C++ types map to Python equivalents (e.g., QuantLib::Rate → float)
  • They can customize behavior with typemaps, directors, and docstrings
  • QuantLib-SWIG uses .i files in the SWIG/ subfolder to describe the entire QuantLib API

During the wrapper build, SWIG reads these .i files and generates intermediate C++ wrapper code, which is then compiled into .so shared libraries that Python can import.

Building QuantLib-SWIG in Debug mode

The key rule is consistency. Thus, SWIG wrappers should be generated and linked against the same QuantLib install (headers + library) that you compiled in debug mode when creating the /quantlib-debug-install folder and its content, since installation must be discoverable during SWIG wrapper build.

The QuantLib-SWIG repository root is not CMake-based (no root CMakeLists.txt), so the wrapper build should follow its Autotools/Python flow. In order to have an isolated environment for QuantLib testing and debug, I have created a python environment, and suggest the reader to do the same. The virtual environment has two purposes: isolation for wheels creation, and isolated testing enfironment, in which the created wheel in this step will be installed. For the sake of this example, I’ve created it in /<path-to-your-venv-folder>/test_debug_quantlib path. Clearly the name of the venv is test_debug_quantlib.

As we’re interested only on python codes now, lets dissable any other supported programming language, by executing the command below. This requires the virtual environment test_debug_quantlib is activated. This step will create a MakeFile within QuantLib-SWIG/Python folder, with the configuration for creating the wrapper.

./configure --disable-csharp --disable-java --disable-r --disable-scala PYTHON="$(which python)"

If you get into the MakeFile just created, there is a key value which determines the environment in which the python wheel will be built. It’s PYTHON = /<path-to-your-venv-folder>/test_debug_quantlib/bin/python. Once we’ve told QuantLib-SWIG we are interested only in Python bindings, we can proceed with the wrapper generation, by executing the commands below.

# Firstly, clone the official repository.
cd $HOME/GIT
git clone https://github.com/lballabio/QuantLib-SWIG.git
cd QuantLib-SWIG

# 1) Activate your VENV
source /<path-to-your-venv-folder>/test_debug_quantlib/bin/activate

# 1.1) Install build library
pip install build

# 2) Setting the debug flags on, and Boost library path for letting the linker to search
export CXXFLAGS="-g3 -O0 -fno-omit-frame-pointer"
export LDFLAGS="-g"
export PATH=$HOME/quantlib-debug-install/bin:$PATH
export VCPKG_BOOST_INC=/<path-to-vcpkg-folder>/vcpkg/installed/x64-linux/include

# 3) Force Make to use the python VENV (being in the VENV activated)
# This avoids to explicitely tell the linker where to look for the shared libraries by means LD_LIBRARY_PATH.
# export LD_LIBRARY_PATH=$HOME/quantlib-debug-install/lib${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH} # << ONLY if working outside the VENV [NOT TESTED]
make -C Python PYTHON="$(python -c 'import sys; print(sys.executable)')" \
  CXXFLAGS="-g3 -O0 -fno-omit-frame-pointer -I$VCPKG_BOOST_INC" \
  LDFLAGS="-Wl,-rpath,$HOME/quantlib-debug-install/lib"

# 3.1) Force Make to use the VENV [Optional] (being in the VENV activated) - Linker Search Paths
make -C Python PYTHON="$(python -c 'import sys; print(sys.executable)')" \
  CXXFLAGS="-g3 -O0 -fno-omit-frame-pointer -I$VCPKG_BOOST_INC" \
  LDFLAGS="-L/<path-to-vcpkg-folder>/vcpkg/installed/x64-linux/lib -Wl,-rpath,/<path-to-vcpkg-folder>/vcpkg/installed/x64-linux/lib"

For debugging, the key in this step lies in the CXXFLAGS. Each is described in table below for technical references. Without this flags, the the generation of the wrapper cannot understand the codes we are generating are aimed to debug, namely, would not include debug symbols.

Flag Purpose Practical effect in this workflow
-g3 Emit rich debug symbols. Enables detailed source-level debugging in tools such as GDB, including macro-level debug info.
-O0 Disable compiler optimizations. Preserves source-like execution flow, making breakpoints, stepping, and variable inspection more reliable.
-fno-omit-frame-pointer Keep frame pointers in generated code. Improves call stack readability and backtrace quality during debugging/profiling.
-I$VCPKG_BOOST_INC Add an extra header include path. Allows the compiler to resolve Boost headers from your VCPKG installation.

For successful linkage, LDFLAGS is equally important because it controls where the linker looks for libraries during build time and which runtime lookup paths are embedded into the generated extension module.

LDFLAGS variant What it does Practical effect in this workflow
-Wl,-rpath,$HOME/quantlib-debug-install/lib Passes an rpath directive to the linker (-Wl, forwards options to ld) so the produced Python extension records $HOME/quantlib-debug-install/lib as a runtime library search path. Helps _QuantLib*.so find libQuantLib.so from your debug install at import time, reducing dependency on manually exporting LD_LIBRARY_PATH.
-L/<path-to-vcpkg-folder>/vcpkg/installed/x64-linux/lib -Wl,-rpath,/<path-to-vcpkg-folder>/vcpkg/installed/x64-linux/lib -L... adds a link-time search directory for resolving dependent libraries, while the rpath part embeds that same directory for runtime resolution. Ensures dependencies provided by VCPKG can be found both when linking and later when Python loads the extension.

At this stage, the commands just executed will create two folders within QuantLib-SWIG/Python: /build and /dist. In practice, build is the working area for intermediate artifacts created during compilation, while dist is the delivery area for distributable packages.

Folder Typical contents Why it matters
/build Temporary and intermediate artifacts such as generated wrapper C/C++ sources, object files, and packaging staging trees (for example lib.*, temp.*, bdist.*). Useful for troubleshooting compile/link issues and checking what SWIG generated before packaging.
/dist Final distributable artifacts, typically wheel files like QuantLib-<version>-*.whl (and sometimes source archives, depending on the invoked packaging command). This is the folder you use to install or share the package artifact.

Voila!!, habemus python wheel with debug symbols!

The Python thing

At this point, you have built QuantLib and its Python bindings with debug symbols, allowing you to trace execution from Python into the C++ implementation. The next step is to install the generated wheel in your Python environment and inspect the files that connect the two layers.

Installing the just created Wheel

As said before, the wheel object, which is used to install libraries in python environment is created within the /build folder. Then the next step is to install it in our testing and debugging environment with the command below (In my case it has generated the wheel with name quantlib-1.43rc0-cp39-abi3-linux_x86_64.whl).

pip install Python/dist/quantlib-1.43rc0-cp39-abi3-linux_x86_64.whl

Once installed, you can check it is correctly installed by listing the libraries instaled in the testing and debugging environment with

pip list

You should see something like the prompt below, in which it’s possible to identify QuantLib version 1.43rc0 is installed.

└─$ pip list              
Package         Version
--------------- -------
build           1.5.0
packaging       26.2
pip             26.1.2
pyproject_hooks 1.2.0
QuantLib        1.43rc0

Let’s dive into the installation

Python libraries installed in virtual environments are located within a subfolder named <path-to-your-virtual-env>/test_debug_quantlib/lib/python3.13/site-packages/. This allows to take a look on its content. Thus, you should normally see _QuantLib*.so and QuantLib.py within the library /QuantLib, which are the outputs of the SWIG wrapper pipeline. Easy to check.

└─$ ls <path-to-your-virtual-env>/test_debug_quantlib/lib/python3.13/site-packages/QuantLib
__init__.py  __pycache__  _QuantLib.abi3.so  QuantLib.py

The _QuantLib*.so file corresponds to the shared library with C++ codes wrapped by SWIG, whereas QuantLib.py contains the pythond escriptors to the C++ codes. How we can infer that?. Pretty easy. LEt’s get back to the folder where you installed QuantLib-SWIG. During the wrapper generation command execution we said a folder named /dist was created. If you get back to that folder you’ll see something like the prompt below.

└─$ ls Python/build/lib.linux-x86_64-cpython-313/QuantLib 
__init__.py  _QuantLib.abi3.so  QuantLib.py

Not for nothing are the same files wrapped in wheel files for distribution, and the same we can see in the /site-package folder.

Point your C++ test project to the Debug install

Aimed to test whether all this effort really works, I want to present two cases below.

Pure C++ test project

To keep this post focused, I moved the full end-to-end testing walkthrough to a dedicated article where the whole workflow is implemented around a European FX option in C++:

Debugging a European FX option in QuantLib C++ with VS Code

That companion post includes a complete example with:

  1. full main.cpp code (Garman-Kohlhagen setup in QuantLib),
  2. CMakeLists.txt explicitly linked to $HOME/quantlib-debug-install,
  3. VS Code tasks.json and launch.json configured for debug execution,
  4. practical guidance on breakpoints, runtime linking, and symbol inspection.

Use it as the validation template for this section: once that FX option runs and debugs correctly, your local QuantLib debug environment is correctly wired.

Combined Python and C++ Debug

The next step is to follow a Python pricing call into QuantLib’s C++ engine and back. The companion post Debugging QuantLib across Python and C++ in VS Code starts with the VS Code configuration, introduces test_debug.py, and walks through the two-debugger handoff for initial pricing and repricing. It explains how to keep the breakpoint sequence intact by attaching both debuggers to the same process and selecting the appropriate session before stepping or continuing.