• Home
  • Integrations
  • SDKs
  • Guides
  • API docs
    No results for ""
    EXPAND ALL

    EDIT ON GITHUB

    C/C++ (client-side) SDK 1.x to 2.0 migration guide

    Read time: 2 minutes
    Last edited: May 13, 2022

    Overview

    This topic explains how to adapt code that currently uses a 1.x version of the C/C++ client-side SDK to use version 2.0.

    To learn more about updating to the latest 2.x version, visit the SDK's GitHub repository.

    Build system changes

    The C/C++ client-side SDK previously used make on POSIX, and nmake on Windows. We have transitioned to the cross platform cmake build system, similar to the C/C++ server-side SDK.

    We recommend that you use the prebuilt releases if they exist for your platform available on the GitHub releases page.

    You can produce a simple build on Linux or OSX by using the following command:

    mkdir build && cd build
    cmake ..
    make

    For more advanced cmake usage, or if you use another platform, read this cmake guide. The SDK is exported as the ldclientapi target.

    You should not consider the repository organization of source files stable. If you want to build your own artifacts and use them outside of a cmake project, cmake install to your directory of choice which will copy the required headers and binary.

    Header and typedef changes

    In version 1.x, the SDK required you to import uthash.h, and ldapi.h. Now, similarly to the C/C++ server-side SDK, you should import the SDK with the following command:

    #include <launchdarkly/api.h>

    The types LDClient, LDConfig, and LDUser are no longer typedefs. They require the struct prefix:

    struct LDClient *client;
    struct LDUser *user;
    struct LDConfig *config;

    In version 1.x of the SDK, when you compiled it with C++, LDClient was defined as a class instead of a C struct. We removed this system in version 2.0, and now LDClient is always a C style struct.

    If you prefer a C++ interface, we added a dedicated LDClientCPP class that shares substantially the same API as you would have used with the 1.x C++ LDClient.

    The entry point for the C++ interface is launchdarkly/api.hpp and you must link with the ldclientapicpp target instead of ldclientapi. As is standard, you can use the standard C interface in a C++ project.

    Logging changes

    We have removed the logging interface from the 1.x versions, which was specific to the client-side SDK. C/C++ client- and server-side SDKs now use the same interface.

    For example, to configure the SDK to use the default included logger:

    LDConfigureGlobalLogger(LD_LOG_INFO, LDBasicLogger);

    JSON representation changes

    The C/C++ client-side SDK 1.x used a JSON representation utilizing the uthash.h library. We removed this old representation completely and now use the C/C++ server-side SDK JSON interface instead. Every function relating to LDNode has been modified to utilize struct LDJSON instead. This includes LDJSONVariation and custom user attributes.

    For example, to create a basic array, use:

    struct LDJSON *names, *tmp;
    names = LDNewArray();
    tmp = LDNewText("alice");
    LDArrayPush(names, tmp);
    tmp = LDNewText("bob");
    LDArrayPush(names, tmp);
    LDJSONFree(names);

    For complete documentation on manipulating JSON, read our API docs on GitHub.