Documentation Index
Fetch the complete documentation index at: https://launchdarkly-preview.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
Overview
This topic documents how to get started with the client-side C++ SDK, and links to reference information on all of the supported features.LaunchDarkly’s SDKs are open source. In addition to this reference guide, we provide source, API reference documentation, and sample applications:
| Resource | Location |
|---|---|
| SDK API documentation | SDK API docs |
| Supported SDK Versions | C++ client SDK |
| GitHub repository | cpp-sdks |
| Sample applications | C++ (client-side) (native) , C++ (client-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.
This SDK is intended for use in single-user mobile, desktop, and embedded applications. If you have a C/C++ application and want to set up LaunchDarkly on the server-side, read the server-side C/C++ SDK reference.To learn more about LaunchDarkly’s different SDK types, read Choosing an SDK type.
Get started
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
- Include the LaunchDarkly headers
- Understand the SDK namespaces
- Initialize the client
- Evaluate a flag
Incorporate the SDK
You can incorporate the SDK by building from source usingcmake, or by using pre-built artifacts. Then, include the LaunchDarkly headers.
Expand Incorporate the SDK using cmake
Expand Incorporate the SDK using cmake
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::clienttarget:
Expand Incorporate the SDK using prebuilt artifacts
Expand Incorporate the SDK using prebuilt artifacts
Incorporate the SDK using prebuilt artifacts
The C++ (client-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](https://github.com/launchdarkly/cpp-sdks/releases?q=%22launchdarkly-cpp-client%
- 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:
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’s artifacts, usecmake installto install the SDK in directory you choose. This copies the required headers, and binaries equivalent to LaunchDarkly’s release bundles.
Include the Launch
Darkly headers To include the LaunchDarkly SDK headers:Understand the SDK namespaces
SDK components common to the C++ (client-side) SDK v3.0 and the C++ (server-side) SDK v3.0 exist within the top-levellaunchdarkly namespace. Client-side components exist within launchdarkly::client_side.
To keep the examples in our documentation concise, we assume symbols in the top-level launchdarkly namespace are visible. You can bring launchdarkly, launchdarkly::client_side, or both into scope, or you can refer to SDK components by their fully-qualified names.
For example:
Initialize the client
After you install the SDK, initialize a single sharedClient. To create a client instance, you need your environment’s mobile key and the context for which you want to evaluate flags. The mobile key authorizes your application to connect to a particular environment within LaunchDarkly.
Here’s how to configure the mobile key and define the context:
ConfigBuilder.
Next, construct the client and call StartAsync to initiate a remote call to the LaunchDarkly service and fetch the feature flag settings for a given context. The StartAsync method returns a future. We strongly recommend using StartAsync with a method that takes a timeout, such as wait_for.
To block on initialization for a specific amount of time:
variation call. Whether you block on initialization or initialize asynchronously, you can examine the result to determine if initialization succeeded.
Here’s how:
StartAsync with wait rather than with wait_for. However, we strongly discourage this. If you block indefinitely, your application will hang if the client cannot connect to LaunchDarkly. To learn more, read StartAsync. If you do choose to block indefinitely for client initialization, you can listen to status updates. To learn more, read Monitoring SDK status.
Evaluate a flag
After you create the client, you can use it to check which variation a particular context will receive for a given feature flag. Here’s how:Shut down the client
Shut down the client when your application terminates. To learn more, read Shutting down.Supported features
This SDK supports the following features:- Anonymous contexts and users
- Configuration, including
- Context configuration
- Evaluating flags
- Flag evaluation reasons
- Flushing events
- Getting all flags
- Identifying and changing contexts
- Monitoring SDK status
- Offline mode
- Private attributes
- Relay Proxy configuration, using proxy mode
- Sending custom events
- Shutting down
- Subscribing to flag changes
- Web proxy configuration