Skip to main content
Public Preview - This version is in public preview and subject to changes. For production use, please use SDK v4.

Installing the C++ SDK

Linux

To install the C++ SDK:
1
Fetch and extract the Ditto package. (Downloading and Unpacking Ditto)
2
Configure your app to link to the Ditto library. (Linking to Ditto)

Downloading and Unpacking Ditto

Download Ditto.tar.gz and unpack an archive containing the libditto.a static library and Ditto header:
curl -O https://software.ditto.live/cpp-linux-x86_64/Ditto/4.11.0/dist/Ditto.tar.gz && tar xvfz Ditto.tar.gz

Linking to Ditto

Add -lditto as a compilation step in the main.cpp source file:
For instructions on adding cross-platform Bluetooth Low Energy (LE) capabilities, see Bluetooth on Linux.BlueZ is the official Bluetooth protocol stack implementation for Linux systems to communicate with other Bluetooth-enabled platforms.
# This command assumes:
# You have unzipped the Ditto.tar.gz in a relative directory ./sdk/
# Your main code entry point is in ./src/main.cpp

g++ -std=c++17 ./src/main.cpp -I ./sdk -lditto -ldl -lrt -pthread -L ./sdk -o dist/main;

 # Once executed, your output will be available at: ./dist/main

Importing and Initializing Ditto

From the source code of your app, using #include <Ditto.h>, use the ditto namespace, and provide your access credentials:
C++
// Your HTTP Cloud URL Endpoint
std::string endpoint = "REPLACE_ME_WITH_YOUR_URL";
std::string id = "REPLACE_ME_WITH_YOUR_DATABASE_ID";

auto config = DittoConfig::default_config()
    .set_database_id(id) // This was "appID" in v4
    .set_connect(DittoConfig::Connect::server(endpoint));

auto ditto = Ditto::open(config);

// Set up authentication expiration handler (required for server connections)
ditto->auth().set_expiration_handler([](auto& ditto, int64_t seconds_remaining) {
    // Authenticate when token is expiring
    ditto.auth().login(
        // Your development token, replace with your actual token
        "REPLACE_ME_WITH_YOUR_DEVELOPMENT_TOKEN",
        // Use Authenticator::get_development_provider() for playground
        Authenticator::get_development_provider(),
        [](auto client_info, auto error) {
            if (error) {
                std::cout << "Authentication failed: " << error->message() << std::endl;
            } else {
                std::cout << "Authentication successful" << std::endl;
            }
        }
    );
});

ditto->start_sync();