SDK quick linksLaunchDarkly SDKs are open source. In addition to this reference guide, we provide source, API reference documentation, and a sample application:
| Resource | Location |
|---|---|
| SDK API documentation | SDK API docs |
| Supported SDK Versions | C++ server SDK |
| GitHub repository | cpp-sdks |
| Sample application | C++ (server-side) (native) C++ (server-side) (C binding) |
| Published module | None |
Prerequisites and dependencies
To use the C++ SDK, you must have the following prerequisites installed on your build machine:- Windows or a POSIX environment (Linux, OSX, BSD)
cmake, version 3.19 or aboveboost, version 1.81 or aboveopenssl, version 1.1 or abovelibpthread, if you are using a POSIX environment
cmake during the build process:
If you are planning to run the C++ SDK test suite, you will also need the following:
You do not need to run the test suite in order to use the SDK.
Get started
**Version 3 of the C++ (server-side) SDK is a native C++ library **Previous versions of this SDK were written in C, with a C++ wrapper available. In version 3.0 and higher, this SDK is written in C++, with a C wrapper available. The code samples below show all options, where applicable.
Incorporate the SDK
You can incorporate the SDK by building from source usingcmake, or by using pre-built artifacts. Then, include the LaunchDarkly headers.
Incorporate the SDK using cmake
To incorporate the SDK usingcmake:
- Clone the GitHub repository as a subdirectory of your project.
-
Update your project’s
CMakeLists.txtto include the SDK repository: -
Link your project’s target against the
launchdarkly::servertarget:
Incorporate the SDK using prebuilt artifacts
The C++ (server-side) SDK releases include 64-bit static and dynamic libraries for Linux, Mac, and Windows. To incorporate the SDK using prebuilt artifacts:- Download the correct release for your platform from the GitHub Releases page.
- Ensure the SDK’s headers are installed on the build system. One way to do this is to clone the GitHub repository and install the headers using
cmake:
Include the LaunchDarkly headers
To include the LaunchDarkly SDK headers:Expand for how to install the SDK if you are using v2.x
Expand for how to install the SDK if you are using v2.x
Here’s how to install the SDK:
- Clone the GitHub repository or download a release archive from the GitHub Releases page.
- Install the SDK locally.
- If you use
cmake, the build system will expect thatboostandopensslexist on the system. Thecmakeconfiguration exports the targetldclientapi. - If you don’t use
cmakeand you cannot use LaunchDarkly artifacts, usecmake installto install the SDK in a directory you choose. This copies the required headers, and binaries equivalent to the LaunchDarkly release bundles.
About the SDK namespaces
SDK components common to the C++ (server-side) SDK v3.0 and the C++ (client-side) SDK v3.0 exist within the top-levellaunchdarkly namespace. Server-side components exist within launchdarkly::server_side.
Individual server-side config builders, for example the LoggingBuilder, are within the launchdarkly::server_side::config::builders namespace. To reduce verbosity of configuration code, you may bring this namespace into scope.
To keep the examples in our documentation concise, we assume symbols in the top-level launchdarkly namespace are visible. You can bring launchdarkly, launchdarkly::server_side, launchdarkly::server_side::config::builders, or all of these into scope, or you can refer to SDK components by their fully-qualified names.
For example:
Initialize the client
The C++ (server-side) SDK uses an SDK keyThe C++ (server-side) SDK uses an SDK key. Keys are specific to each and . They are available on the SDK keys page under Settings. To learn more about key types, read Keys.
Client. To create a client instance, you need your environment’s SDK key to authorize your application to connect to a particular environment within LaunchDarkly.
Here’s how to configure the SDK key and create the client:
ConfigBuilder.
Next, construct the client and call StartAsync to initiate a request to the LaunchDarkly service and fetch the feature flag settings.
Because the client initializes asynchronously, you may choose to block until the client is ready.
To block on initialization:
maxwait. If you request a feature flag before initialization completes, you will receive the you defined in your variation call.
Evaluate a context
Now you can check which a specific should receive for a given feature flag. Here’s how:Shut down the client
Lastly, shut down the client when your application terminates. In the C++ SDK v3.0, the SDK will be automatically closed. If you are using the C binding, or if you are working with earlier versions of the SDK, you must specifically close the client. To learn more, read Shutting down.Supported features
This SDK supports the following features:- SDK configuration, including
- Anonymous contexts and users
- Big segments
- Context configuration
- Flag variation evaluation
- Flag variation evaluation details
- Flushing events
- Getting all flags
- Identifying and changing contexts
- Logging configuration
- Monitoring SDK status
- Offline mode
- Private attributes
- Relay Proxy configuration
- Runtime Delivery Network
- Tracking custom events
- Shutting down
- Storing data