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
- Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
-
Install the Google Cloud CLI.
-
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity .
-
To initialize the gcloud CLI, run the following command:
gcloud init
-
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.
-
Verify that billing is enabled for your Google Cloud project .
-
Enable the Cloud Storage API:
Roles required to enable APIs
To enable APIs, you need the Service Usage Admin IAM role (
roles/serviceusage.serviceUsageAdmin), which contains theserviceusage.services.enablepermission. Learn how to grant roles .gcloud services enable storage.googleapis.com
-
Install the Google Cloud CLI.
-
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity .
-
To initialize the gcloud CLI, run the following command:
gcloud init
-
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.
-
Verify that billing is enabled for your Google Cloud project .
-
Enable the Cloud Storage API:
Roles required to enable APIs
To enable APIs, you need the Service Usage Admin IAM role (
roles/serviceusage.serviceUsageAdmin), which contains theserviceusage.services.enablepermission. Learn how to grant roles .gcloud services enable storage.googleapis.com
-
Create a Cloud Storage bucket run the examples:
- Ensure that you have the Storage Admin role
(
roles/storage.admin) on the project. Learn how to grant roles . - Create a Cloud Storage bucket:
Replacegcloud storage buckets create gs:// BUCKET_NAME
BUCKET_NAMEwith a bucket name that meets the bucket naming requirements .
- Ensure that you have the Storage Admin role
(
- Ensure that the following tools are installed:
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.

