Getting started with C/C++ Client SDK

2 minute read

This section describes how to set up and install the C/C++ SDK and how to deploy a feature flag.

Step 1 - Setting up the C/C++ Client SDK

To setup the C/C++ SDK, follow these steps:

  1. Create a CloudBees Feature Management account. See Signup Page to create an account.

  2. Get your environment key. Copy your environment key from App settings > Environments > Key.

Step 2 - Installing the C/C++ Client SDK

  1. For instructions on installing the C/C++ package in your application, select your operating system:

Linux or macOS

  1. Install the prerequisites:

    Linux
    macOS
    $ apt-get install cmake gcc git
    $ brew install cmake gcc git
  2. Clone the Rox C SDK Repository at the root of the workspace directory.

    $ git clone https://github.com/rollout/rox-c.git
  3. Run the installation script. This will install the SDK to the subdirectory specified in the command. If the optional -p parameter is omitted, the installation will require superuser privileges, and the SDK will be installed at /usr/local/rollout-sdk.

    $ cd rox-c && ./install.sh -d /path/to/install/dir

Windows

  1. To make sure the OpenSSL and Curl libraries can be built on Windows, install the following and ensure the executables are added to PATH:

  2. Open Cross Tools Command Prompot for VS.

  3. Clone the repository:

    > git clone https://github.com/rollout/
  4. Navigate to the repository root folder.

  5. Install the SDK to the desired %INSTALLATION_PATH%. If omitted, the SDK will require Administrator permissions, to install at C:\Program Files\rollout-sdk.

    > install %INSTALLATION_PATH%
  6. (OPTIONAL) add %INSTALLATION_PATH%\bin to system PATH variable.

Add the following lines of code to your application

C
C++
#include <rox/client.h> #include <stdio.h> #define DEFAULT_API_KEY <CBFF_ENV_KEY> #define DEFAULT_DEV_MODE_KEY "null" int main(int argc, char **argv) { RoxStringBase *demo_flag = rox_add_flag_with_freeze("demo.demoFlag", false, RoxFreezeUntilLaunch); RoxOptions *options = rox_options_create(); rox_options_set_dev_mode_key(options, DEFAULT_DEV_MODE_KEY); rox_setup(DEFAULT_API_KEY, options); char c = 'Y'; while (c != 'n' && c != 'N') { printf("Demo flag is %s\n", rox_flag_is_enabled(demo_flag) ? "ON" : "OFF"); printf("Continue? (Y/n):"); c = fgetc(stdin); if ((c == '\n' || c == EOF)) { // Enter key pressed c = 'Y'; } else { getchar(); // read dummy character to clear input buffer, which inserts after character input } printf("\n"); } rox_shutdown(); return 0; }
#include <roxx/client.h> #include <cstdio> #define DEFAULT_API_KEY <CBFF_ENV_KEY> #define DEFAULT_DEV_MODE_KEY "null" int main(int argc, char **argv) { Rox::Client::Flag *demoFlag = Rox::Client::Flag::Create("demo.demoFlag", false, RoxFreezeUntilLaunch); Rox::Options *options = Rox::OptionsBuilder() .SetDevModeKey(DEFAULT_DEV_MODE_KEY) .Build(); Rox::Setup(DEFAULT_API_KEY, options); char c = 'Y'; while (c != 'n' && c != 'N') { printf("Demo flag is %s\n", demoFlag->IsEnabled() ? "ON" : "OFF"); printf("Continue? (Y/n):"); c = fgetc(stdin); if ((c == '\n' || c == EOF)) { // Enter key pressed c = 'Y'; } else { getchar(); // read dummy character to clear input buffer, which inserts after character input } printf("\n"); } Rox::Shutdown(); return 0; }

Container class registration and environment key setup

  • You cannot call Rox.setup() twice in the same runtime.

Run your application

Running the application

The flag name is automatically added to the CloudBees Feature Management dashboard after running the application.