# Run C++ Examples in Cloud Shell

Learn how to compile and run the C++ client examples in Cloud Shell using
[micromamba](https://mamba.readthedocs.io/en/latest/micromamba-installation.html)
and [Conda](https://conda.io/)

## Before you begin

1. Create a Cloud Storage bucket run the examples:

   1. Ensure that you have the Storage Admin role (`roles/storage.admin`) on the project. [Learn how to
      grant roles](https://docs.cloud.google.com/iam/docs/granting-changing-revoking-access).
   2. Create a Cloud Storage bucket:

      ```bash
      gcloud storage buckets create gs://BUCKET_NAME
      ```
      Replace `BUCKET_NAME` with a bucket name that meets the [bucket naming requirements](https://docs.cloud.google.com/storage/docs/buckets#naming).
2. Ensure that the following tools are installed:
   - [Curl](https://curl.se/download.html)
   - [Git](https://git-scm.com/downloads)

<br />

## 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:

       gcloud storage rm gs://BUCKET_NAME/quickstart.txt

2. Delete the bucket:

       gcloud storage buckets delete gs://BUCKET_NAME

## What's next

- Find more [C++ examples](https://docs.cloud.google.com/docs/samples/?language=cpp).
- Deploy a [C++ application](https://github.com/GoogleCloudPlatform/cpp-samples/tree/main/getting-started) to Cloud Run and Google Kubernetes Engine.