Compiling on Linux

This section provides instructions on how to compile shared objects and executable files on Linux. We will use RedHat as an example.

Compiling Shared Libraries

Prerequisites

Make sure you have an environment set up with:

yum install openssl-devel
yum install libuuid-devel

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

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

Compilation

Execute the following commands in terminal to compile libDolphinDBAPI.so:

cd path/to/api-cplusplus
mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Release -DUSE_AERON=OFF -DUSE_OPENSSL=ON
make -j4

Description of cmake parameters:

  • -DCMAKE_BUILD_TYPE=Release: Compiles the Release version.
  • -DUSE_AERON=OFF: Does not link the Aeron library, i.e., does not compile the multicast stream subscription-related code.
  • -DAERON_INSTALL_DIR=<aeron_install_path>: Specifies the location of the Aeron library in a non-default system path for correct linking. If you are not linking the Aeron library or it is installed in the system’s default path, this parameter is not needed.
  • -DUSE_OPENSSL=ON: This parameter must be specified if you want to use OpenSSL to encrypt the communication between the API and DolphinDB. When specified, the SSL and Crypto dynamic libraries will be linked when compiling the API dynamic library.
  • -DDOPENSSL_ROOT_DIR=/path/to/openssl: If OpenSSL is not installed in the default directory, you can specify the OpenSSL path with this parameter.

Compiling Executable Files

  1. Copy the DolphinDBAPI.so in the ../api-cplusplus/build (generated in Compiling Shared Libraries) into the demo/lib directory.
  2. Run the following commands in terminal:
    cd path/to/api-cplusplus/demo
    mkdir build && cd build
    cmake .. -DABI=0 -DUSE_OPENSSL=1 -DOPENSSL_PATH=/home/openssl/
    cmake --build .

    Description of cmake parameters:

    • -DABI=0: Specifies the value of _GLIBCXX_USE_CXX11_ABI during compilation. It can be set to 1 or 0. Note that the value of ABI must be the same.
    • -DUSE_OPENSSL=1: This parameter must be specified if you want to use OpenSSL to encrypt the communication between the API and DolphinDB. When specified, the SSL and Crypto dynamic libraries will be linked when compiling the API dynamic library.
    • -DOPENSSL_PATH=/path/to/openssl: If OpenSSL is not installed on the system, you can specify the OpenSSL path using this parameter.
  3. The generated executable file apiDemo is stored in the demo/bin directory.