Compiling on Windows

This section provides instructions on how to compile dynamic-link library and executable files on Windows. We will employ two approaches, Visual Studio 2022 and MinGW.

With Visual Studio 2022

Compiling Shared Libraries

Prerequisites

Make sure you have an environment set up with:

Download the code from the api-cplusplus project in Github. Take the main branch as an example, run the following commands in Git Bash:
git clone git@github.com:dolphindb/api-cplusplus.git
git checkout -b main origin/main

Compilation

Execute the following commands in PowerShell to compile DolphinDBAPI.dll and DolphinDBAPI.lib:
cd path/to/api-cplusplus
mkdir build && cd build
cmake .. -G "Visual Studio 17 2022" -A x64 -DUSE_OPENSSL=1 -DOPENSSL_PATH=D:/temp/openssl-1.0.2l-vs2017 -DCMAKE_CONFIGURATION_TYPES="Release;Debug"
cmake --build . --config Release

Options for generating a project buildsystem:

  • -G: <generator-name> specifies a build system generator.
  • -A: <platform-name> specifies the target platform. x64 means to generate 64-bit dynamic-link libraries, and x86 to generate 32-bit dynamic-link libraries.
  • -D: <var>=<value>
    • USE_OPENSSL=1: It must be specified if you want to use OpenSSL to encrypt communication between the API and DolphinDB. The SSL and crypto libraries will be dynamically linked to the API during the compilation process.
    • OPENSSL_PATH=/path/to/openssl: specifies the OpenSSL path if OpenSSL is not installed on your system.
    • CMAKE_CONFIGURATION_TYPES="Release;Debug": specifies the available build types (configurations) on Visual Studio. Here, it supports “Release” or “Debug” type.

Options for building a project:

  • --config: specifies the build target. Here, we configure it as Release. You can change it to Debug.
Note: If you want to compile 64-bit dynamic-link libraries with the OpenSSL libraries downloaded from the provided URL, you need to delete the 32-bit bin, include, and lib folders in the download directory. Then, rename the existing 64-bit bin64, include64, and lib64 folders to bin, include, and lib respectively. After updating the folder names, you can execute the cmake command to compile the 64-bit dynamic-link libraries.

Compiling Executable Files

(1) Copy the DolphinDBAPI.lib in the ../api-cplusplus/Release (generated in Compiling Shared Libraries) into the demo/lib directory.

(2) Run the following commands in PowerShell:

cd path/to/api-cplusplus/demo
mkdir build && cd build
cmake .. -G "Visual Studio 17 2022" -A x64 -DUSE_OPENSSL=1 -DOPENSSL_PATH=D:/temp/openssl-1.0.2l-vs2017 -DCMAKE_CONFIGURATION_TYPES="Release;Debug"
cmake --build . --config Release

The generated executable file apiDemo.exe is stored in the demo/bin/Release directory.

(3) Copy the following dynamic-link library to the demo/bin/Release directory.

  • DolphinDBAPI.dll (located in ../api-cplusplus/Release)
  • libeay32MD.dll (located in ../openssl-1.0.2l-vs2017/bin)
  • ssleay32MD.dll (located in ../openssl-1.0.2l-vs2017/bin)

With MinGW

Compiling Shared Libraries

Prerequisites

Make sure you have an environment set up with:

  • Installation: MinGW, Git, CMake
  • Downloads: OpenSSL Library (You can find a precompiled OpenSSL library in ../api-cplusplus/lib/openssl-1.0.2u. We will use this library for an example here)

Download the code from the api-cplusplus project in Github. Take the main branch as an example, run the following commands in Git Bash:

git clone git@github.com:dolphindb/api-cplusplus.git
git checkout -b main origin/main

Compilation

Execute the following commands in PowerShell to compile DolphinDBAPI.dll:

cd path/to/api-cplusplus
mkdir build && cd build
cmake .. -G "MinGW Makefiles" -DUSE_OPENSSL=1 -DOPENSSL_PATH=D:/workspace/testCode/api-cplusplus/lib/openssl-1.0.2u/openssl-1.0.2u/static
cmake --build .

Options for generating a project buildsystem:

  • -G: <generator-name> specifies a build system generator.
  • -D: <var>=<value>
    • USE_OPENSSL=1: It must be specified if you want to use OpenSSL to encrypt communication between the API and DolphinDB. The SSL and crypto libraries will be dynamically linked to the API during the compilation process.
    • OPENSSL_PATH=/path/to/openssl: specifies the OpenSSL path if OpenSSL is not installed on your system.

Compiling Executable Files

(1) Copy the DolphinDBAPI.dll in the ../api-cplusplus/build(generated in Compiling Shared Libraries) into the demo/lib directory.

(2) Run the following commands in PowerShell:

cd path/to/api-cplusplus/demo
mkdir build && cd build
cmake .. -G "MinGW Makefiles" -DUSE_OPENSSL=1 -DOPENSSL_PATH=D:/workspace/testCode/api-cplusplus/lib/openssl-1.0.2u/openssl-1.0.2u/static
cmake --build .

The generated executable file apiDemo.exe is stored in the demo/bin directory.

(3) Copy the following dynamic-link libraries (compiled in [the above section]) to the demo/bin directory.

  • DolphinDBAPI.dll (located in ../api-cplusplus/build)
  • libeay32MD.dll (located in ../openssl-1.0.2u/static/bin)
  • ssleay32MD.dll (located in ../openssl-1.0.2u/static/bin)