Run C++ Examples in Cloud Shell

Learn how to compile and run the C++ client examples in Cloud Shell using micromamba and Conda

Before you begin

  1. In the Google Cloud console, activate Cloud Shell.

    Activate Cloud Shell

  2. Create or select a Google Cloud project.

    • Create a Google Cloud project:

      gcloud projects create PROJECT_ID

      Replace PROJECT_ID with a name for the Google Cloud project you are creating.

    • Select the Google Cloud project that you created:

      gcloud config set project PROJECT_ID

      Replace PROJECT_ID with your Google Cloud project name.

  3. Create a Cloud Storage bucket:
    gcloud storage buckets create gs://BUCKET_NAME
    Replace BUCKET_NAME with a bucket name that meets the bucket naming requirements.

Install pre-compiled C++ Client Libraries in Cloud Shell

  1. In Cloud Shell, install micromamba:

    curl -fsSL https://micro.mamba.pm/api/micromamba/linux-64/latest | sudo tar -C /usr -xj bin/micromamba
    
  2. Add micromamba hooks to the current shell:

    eval "$(/usr/bin/micromamba shell hook -s posix)"
    
  3. Use micromamba to create a Conda environment with the necessary development tools and libraries:

    micromamba create -y -n base -c conda-forge cmake ninja cxx-compiler google-cloud-cpp libgoogle-cloud
    
  4. Activate the new conda environment:

    micromamba activate
    

Checkout and compile the "Storage Quickstart" example

  1. Checkout the C++ Client Library source code, including the quickstart examples for all services:

    git clone --depth 1 https://github.com/googleapis/google-cloud-cpp
    
  2. Configure CMake to compile the "Storage Quickstart" example:

    cmake -S google-cloud-cpp/google/cloud/storage/quickstart -B .build
    
  3. Compile the example:

    cmake --build .build
    
  4. Run the example:

    .build/quickstart BUCKET_NAME
    
  5. After running this example, you'll see a message similar to Successfully created object ... followed by data specific to your object and ending with a line that shows Hello World!.

Clean up

To avoid incurring charges to your Google Cloud account for the resources used on this page, delete the Google Cloud project with the resources.

  1. Delete the object created by the example:

    gsutil rm gs://BUCKET_NAME/quickstart.txt
    
  2. Delete the bucket:

    gsutil rb gs://BUCKET_NAME
    

What's next