Skip to main content

Use the Lattice SDK for gRPC in C++

This page shows you how to set up the Lattice SDK for gRPC in C++ and make a gRPC request.

Click to go to the gRPC SDK repository. By downloading and/or using, you agree to the terms of use. If you do not agree, do not use the SDK.

Before you begin

Before you install and use the Lattice SDK in C++, do the following:

  1. Set up your development environment.

  2. Install CMake version 3.16 or greater.

  3. Install gRPC versions 1.68.0 and Protobuf version 29.0.0.

    C++ requires the versions to be an exact match between its generated code version and its runtime version at all times. For more information or to use alternative versions, see C++ requirements.

Define the CMakeLists.txt

  1. Run the following command to create, and navigate to, a new project folder

    mkdir lattice-sdk-example && cd lattice-sdk-example
  2. Copy and paste the following to define your CMakeLists.txt file. The CMakeLists.txt file defines your project's basic properties and its dependencies, including the Lattice SDK in C++. You also define your executable here. In the following example, your executable is called cli_client. You'll use this executable file to run your application:

    warning

    Use the latest version of GIT_TAG to avoid issues from gRPC or Protobuf dependency updates, as it includes the specific versions used for building.

    cmake_minimum_required(VERSION 3.25.0)
    project(lattice-sdk-example)

    set(CMAKE_CXX_STANDARD 17)
    set(CMAKE_CXX_STANDARD_REQUIRED ON)

    # Download the SDK from github and add it as part of the project
    include(FetchContent)
    FetchContent_Declare(
    lattice-sdk-cpp
    GIT_REPOSITORY https://github.com/anduril/lattice-sdk-cpp.git
    GIT_TAG v1.0.0
    )
    FetchContent_MakeAvailable(lattice-sdk-cpp)

    # Build the text-only CLI and link against the Lattice SDK.
    add_executable(cli_client main.cpp)
    target_link_libraries(cli_client lattice-sdk-cpp)

Install the SDK

Install the gRPC SDK in C++:

  1. Create and navigate into a new build folder in the lattice-sdk-example project.
    mkdir build && cd build/
  2. Use cmake to install the Lattice C++ SDK, as configured in CMakeLists.txt.
    cmake ..
    If successful, this command installs the dependencies, including the Lattice SDK.

What's next