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.
-
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.
-
-
Create a Cloud Storage bucket:
gcloud storage buckets create gs://BUCKET_NAME
ReplaceBUCKET_NAME
with 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
micromamba
hooks to the current shell:eval "$(/usr/bin/micromamba shell hook -s posix)"
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
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.