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
-
In the Google Cloud console, activate Cloud Shell.
-
Create or select a Google Cloud project .
Roles required to select or create a project
- Select a project : Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
- Create a project
: To create a project, you need the Project Creator role
(
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles .
-
Create a Google Cloud project:
gcloud projects create PROJECT_IDReplace
PROJECT_IDwith a name for the Google Cloud project you are creating. -
Select the Google Cloud project that you created:
gcloud config set project PROJECT_IDReplace
PROJECT_IDwith your Google Cloud project name.
- Create a Cloud Storage bucket:
Replacegcloud storage buckets create gs:// BUCKET_NAME
BUCKET_NAMEwith a bucket name that meets the bucket naming requirements .
Install pre-compiled C++ Client Libraries in Cloud Shell
-
In Cloud Shell, install
micromamba:curl -fsSL https://micro.mamba.pm/api/micromamba/linux-64/latest | sudo tar -C /usr -xj bin/micromamba -
Add
micromambahooks to the current shell:eval " $( /usr/bin/micromamba shell hook -s posix ) " -
Use
micromambato 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 -
Activate the new conda environment:
micromamba activate
Checkout and compile the "Storage Quickstart" example
-
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 -
Configure CMake to compile the "Storage Quickstart" example:
cmake -S google-cloud-cpp/google/cloud/storage/quickstart -B .build -
Compile the example:
cmake --build .build -
Run the example:
.build/quickstart BUCKET_NAME -
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 showsHello 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.
-
Delete the object created by the example:
gcloud storage rm gs:// BUCKET_NAME /quickstart.txt -
Delete the bucket:
gcloud storage buckets delete gs:// BUCKET_NAME
What's next
- Find more C++ examples .
- Deploy a C++ application to Cloud Run and Google Kubernetes Engine.

