Overview

This page covers build configuration topics beyond the standard CMake setup described in C / C++ Monitoring Setup. It includes instructions for integrating the SDK into projects that don’t use CMake.

CMake targets and datadog_enable()

To add the SDK as a dependency in your CMake project, pass your executable target to datadog_enable():

add_executable(my-app main.cpp)
datadog_enable(my-app)

This function adds the SDK as a dependency while also configuring additional build steps as required by your build configuration.

If you prefer to configure CMake dependencies directly, you can use the Datadog::sdk target:

target_link_libraries(my-app PRIVATE Datadog::sdk)

See DatadogConvenience.cmake for a full definition of datadog_enable().

CMake installation rules and datadog_install()

Depending on build configuration, you may need to package additional files with installable builds of your application.

If you’re using install() to define installation rules for your CMake project, call datadog_install():

install(TARGETS my-app RUNTIME DESTINATION bin LIBRARY DESTINATION lib)
datadog_install(my-app
   RUNTIME_DESTINATION bin  # Optional, defaults to CMAKE_INSTALL_BINDIR if set
   LIBRARY_DESTINATION lib  # Optional, defaults to CMAKE_INSTALL_LIBDIR if set
                            # (Not used for Windows or static-library builds)
)

This function deploys all required runtime artifacts alongside your application binary when using cmake --install or building generated “install” targets.

See DatadogConvenience.cmake for a full definition of datadog_install().

Customizing the SDK build

You can customize the SDK build with CMake options when building from source using FetchContent or when creating precompiled binaries for a non-CMake build:

  • In a CMakeList.txt or .cmake file: set(DD_CRASH_MODE inprocess)
  • When configuring the project with cmake: cmake -DDD_CRASH_MODE=inprocess ...
  • In the CMake GUI

These are several important options to consider when building the SDK from source.

OptionDescription
CMAKE_BUILD_TYPEThis is a standard CMake option, typically RelWithDebInfo or Release for production builds. If you incorporate the SDK as a dependency with FetchContent, you are responsible for setting this option in your project's build.
DD_BUILD_SHAREDOFF: The SDK is built as a static library.
ON: The SDK is built as a shared/dynamic library.
Defaults to the value of BUILD_SHARED_LIBS, which is OFF by default.
DD_CRASH_MODEinprocess (default): The SDK uses an in-process handler to detect crashes.
noop: The SDK does not detect crashes.
DD_HTTP_USE_SYSTEM_LIBCURLOFF: libcurl is built from source as a static library and linked into the SDK.
ON: The SDK uses system-installed shared libraries for libcurl.
Defaults to OFF for Windows builds, ON for Linux and macOS.

For a full list of configuration options, see the SDK source.

Integrating the SDK into a non-CMake build

If your application is not built with CMake, you can link against libddsdkcpp.a (or ddsdkcpp.lib on Windows) using your project’s build system. You have two options for obtaining a ready-to-link build of the SDK:

  1. Use precompiled binaries: download an officially-published Datadog release.
  2. Build from source: clone the SDK and build it yourself.

Using precompiled binaries

From the SDK’s GitHub Releases page, find your chosen release, then download the archive for your platform. Extract its contents to a directory within your project: the example below uses external/datadog-sdk/.

Building from source

Alternatively, you can build your own SDK binaries. Clone the SDK, configure it with your desired CMake options, run a build, and then use cmake --install to deploy it to a directory within your project. For example:

git clone https://github.com/DataDog/dd-sdk-cpp.git
cd dd-sdk-cpp
cmake -GNinja -DCMAKE_BUILD_TYPE=RelWithDebInfo -S . -B build
cmake --build build
cmake --install build --prefix "$YOUR_PROJECT/external/datadog-sdk/"
git clone https://github.com/DataDog/dd-sdk-cpp.git
cd dd-sdk-cpp
cmake -G"Visual Studio 17 2022" -S . -B build
cmake --build build --config RelWithDebInfo
cmake --install build --config RelWithDebInfo --prefix "%YOUR_PROJECT%\external\datadog-sdk"

This populates external/datadog-sdk/, placing all required files in include/, lib/, etc.

Configuring compiler and linker dependencies

After preparing a redistributable build of the SDK, make the following changes to your project’s build configuration:

  • Include directories: Add external/datadog-sdk/include/
  • Library directories: Add external/datadog-sdk/lib/
  • Libraries to link: Add -lddsdkcpp on POSIX; ddsdkcpp.lib on Windows

You may also need to add a few other libraries, depending on your platform:

On Linux, linking against the SDK requires:

  • -luuid
  • -lcurl (unless the SDK is built with DD_HTTP_USE_SYSTEM_LIBCURL=OFF)

On macOS, linking against the SDK requires:

  • -framework CoreFoundation
  • -lcurl (unless the SDK is built with DD_HTTP_USE_SYSTEM_LIBCURL=OFF)

On Windows, linking against the SDK requires:

  • ole32.lib
  • wbemuuid.lib

MSVC should include these libraries automatically thanks to #pragma directives.

Deploying additional files

If you’ve built the SDK as a shared library, bundle the shared library with your application:

  • Linux: libddsdkcpp.so
  • macOS: libddsdkcpp.dylib
  • Windows: ddsdkcpp.dll

On macOS and Linux, your executable’s runtime search path must also include the location of this file.

Further Reading