This directory contains small examples showing how to use the Cloud Bigtable C++ client library in your own project. These instructions assume that you have some experience as a C++ developer and that you have a working C++ toolchain (compiler, linker, etc.) installed on your platform.
To run the quickstart examples you will need a working Google Cloud Platform (GCP) project, as well as a Cloud Bigtable instance and table. The Cloud Bigtable quickstart covers the necessary steps in detail. Make a note of the GCP project id, the instance id, and the table id as you will need them below.
Like most Google Cloud Platform (GCP) services, Cloud Bigtable requires that
your application authenticates with the service before accessing any data. If
you are not familiar with GCP authentication please take this opportunity to
review the Authentication Overview. This library
uses the GOOGLE_APPLICATION_CREDENTIALS
environment variable to find the
credentials file. For example:
Shell | Command |
---|---|
Bash/zsh/ksh/etc. | export GOOGLE_APPLICATION_CREDENTIALS=[PATH] |
sh | GOOGLE_APPLICATION_CREDENTIALS=[PATH]; export GOOGLE_APPLICATION_CREDENTIALS |
csh/tsch | setenv GOOGLE_APPLICATION_CREDENTIALS [PATH] |
Windows Powershell | $env:GOOGLE_APPLICATION_CREDENTIALS=[PATH] |
Windows cmd.exe | set GOOGLE_APPLICATION_CREDENTIALS=[PATH] |
Setting this environment variable is the recommended way to configure the authentication preferences, though if the environment variable is not set, the library searches for a credentials file in the same location as the Cloud SDK. For more information about Application Default Credentials, see https://cloud.google.com/docs/authentication/production
⚠️ If you are using Windows or macOS there are additional instructions at the end of this document.
-
Install Bazel using the instructions from the
bazel.build
website. -
Compile this example using Bazel:
cd $HOME/google-cloud-cpp/google/cloud/bigtable/quickstart bazel build ...
Note that Bazel automatically downloads and compiles all dependencies of the project. As it is often the case with C++ libraries, compiling these dependencies may take several minutes.
-
Run the example, change the place holder to appropriate values:
bazel run :quickstart -- [GCP PROJECT] [CLOUD BIGTABLE INSTANCE] [CLOUD BIGTABLE TABLE]
⚠️ If you are using Windows or macOS there are additional instructions at the end of this document.
-
Install CMake. The package managers for most Linux distributions include a package for CMake. Likewise, you can install CMake on Windows using a package manager such as chocolatey, and on macOS using homebrew. You can also obtain the software directly from the cmake.org site.
-
Install the dependencies with your favorite tools. As an example, if you use vcpkg:
cd $HOME/vcpkg ./vcpkg install google-cloud-cpp
Note that, as it is often the case with C++ libraries, compiling these dependencies may take several minutes.
-
Configure CMake, if necessary, configure the directory where you installed the dependencies:
cd $HOME/gooogle-cloud-cpp/google/cloud/bigtable/quickstart cmake -H. -B.build -DCMAKE_TOOLCHAIN_FILE=$HOME/vcpkg/scripts/buildsystems/vcpkg.cmake cmake --build .build
-
Run the example, change the place holder to appropriate values:
.build/quickstart [GCP PROJECT] [CLOUD BIGTABLE INSTANCE] [CLOUD BIGTABLE TABLE]
gRPC requires an environment variable to configure the trust store for SSL certificates, you can download and configure this using:
curl -Lo roots.pem https://raw.githubusercontent.com/grpc/grpc/master/etc/roots.pem
export GRPC_DEFAULT_SSL_ROOTS_FILE_PATH="$PWD/roots.pem"
To workaround a bug in Bazel, gRPC requires this flag on
macOS builds, you can add the option manually or include it in your .bazelrc
file:
bazel build --copt=-DGRPC_BAZEL_BUILD ...
To correctly configure the MSVC runtime you should change the CMake minimum
required version to 3.15 or add -DCMAKE_POLICY_DEFAULT_CMP0091=NEW
to the
CMake configuration step.
gRPC requires an environment variable to configure the trust store for SSL certificates, you can download and configure this using:
@powershell -NoProfile -ExecutionPolicy unrestricted -Command ^
(new-object System.Net.WebClient).Downloadfile( ^
'https://raw.githubusercontent.com/grpc/grpc/master/etc/roots.pem', ^
'roots.pem')
set GRPC_DEFAULT_SSL_ROOTS_FILE_PATH=%cd%\roots.pem