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 .. -DABI=0 -DUUID_PATH=/home/uuid/ -DUSE_OPENSSL=1 -DOPENSSL_PATH=/home/openssl/
make -j4

-D arguments of cmake:

  • ABI=0: specifies the value of _GLIBCXX_USE_CXX11_ABI. It can be set to 0 or 1.
  • UUID_PATH=/path/to/uuid: specifies the UUID path if UUID is not installed on your system. CMake will look for header files in the ${UUID_PATH}/include directory and UUID libraries in the ${UUID_PATH}/lib directory.
  • 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.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 .

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