• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

BUILDH A D01-Dec-2020837 2824

MakefileH A D01-Dec-20201.4 KiB3610

README.mdH A D01-Dec-20204.8 KiB12190

WORKSPACEH A D01-Dec-20201.8 KiB5240

quickstart.ccH A D01-Dec-20201.9 KiB6136

README.md

1# HOWTO: using the Google Cloud Storage (GCS) C++ client in your project
2
3This directory contains small examples showing how to use the GCS C++ client
4library in your own project. These instructions assume that you have some
5experience as a C++ developer and that you have a working C++ toolchain
6(compiler, linker, etc.) installed on your platform.
7
8## Before you begin
9
10To run the quickstart examples you will need a working Google Cloud Platform
11(GCP) project and an existing bucket.
12The [GCS quickstarts](https://cloud.google.com/storage/docs/quickstarts) cover
13the necessary steps in detail. Make a note of the GCP project id and the bucket
14name as you will need them below.
15
16## Configuring authentication for the C++ Client Library
17
18Like most Google Cloud Platform services, GCS requires that
19your application authenticates with the service before accessing any data. If
20you are not familiar with GCP authentication please take this opportunity to
21review the [Authentication Overview][authentication-quickstart]. This library
22uses the `GOOGLE_APPLICATION_CREDENTIALS` environment variable to find the
23credentials file. For example:
24
25| Shell              | Command                                        |
26| :----------------- | ---------------------------------------------- |
27| Bash/zsh/ksh/etc.  | `export GOOGLE_APPLICATION_CREDENTIALS=[PATH]` |
28| sh                 | `GOOGLE_APPLICATION_CREDENTIALS=[PATH];`<br> `export GOOGLE_APPLICATION_CREDENTIALS` |
29| csh/tsch           | `setenv GOOGLE_APPLICATION_CREDENTIALS [PATH]` |
30| Windows Powershell | `$env:GOOGLE_APPLICATION_CREDENTIALS=[PATH]`   |
31| Windows cmd.exe    | `set GOOGLE_APPLICATION_CREDENTIALS=[PATH]`    |
32
33Setting this environment variable is the recommended way to configure the
34authentication preferences, though if the environment variable is not set, the
35library searches for a credentials file in the same location as the [Cloud
36SDK](https://cloud.google.com/sdk/). For more information about *Application
37Default Credentials*, see
38https://cloud.google.com/docs/authentication/production
39
40## Using with Bazel
41
421. Install Bazel using [the instructions][bazel-install] from the `bazel.build`
43   website.
44
452. Compile this example using Bazel:
46
47   ```bash
48   cd $HOME/google-cloud-cpp/google/cloud/storage/quickstart
49   bazel build ...
50   ```
51
52   Note that Bazel automatically downloads and compiles all dependencies of the
53   project. As it is often the case with C++ libraries, compiling these
54   dependencies may take several minutes.
55
563. Run the example, change the place holder to appropriate values:
57
58   ```bash
59   bazel run :quickstart -- [GCP PROJECT] [BUCKET NAME]
60   ```
61
62   Please use the plain bucket name. Do **not** include any `gs://` prefix, and
63   keep in mind the [bucket naming restrictions][bucket-naming-link]. For
64   example, bucket names cannot include forward slashes (`/`) or uppercase
65   letters.
66
67[bucket-naming-link]: https://cloud.google.com/storage/docs/naming-buckets
68
69## Using with CMake
70
711. Install CMake. The package managers for most Linux distributions include a
72   package for CMake. Likewise, you can install CMake on Windows using a package
73   manager such as [chocolatey][choco-cmake-link], and on macOS using
74   [homebrew][homebrew-cmake-link]. You can also obtain the software directly
75   from the [cmake.org](https://cmake.org/download/) site.
76
772. Install the dependencies with your favorite tools. As an example, if you use
78   [vcpkg](https://github.com/Microsoft/vcpkg.git):
79
80   ```bash
81   cd $HOME/vcpkg
82   ./vcpkg install google-cloud-cpp
83   ```
84
85   Note that, as it is often the case with C++ libraries, compiling these
86   dependencies may take several minutes.
87
883. Configure CMake, if necessary, configure the directory where you installed
89   the dependencies:
90
91   ```bash
92   cd $HOME/gooogle-cloud-cpp/google/cloud/storage/quickstart
93   cmake -H. -B.build -DCMAKE_TOOLCHAIN_FILE=$HOME/vcpkg/scripts/buildsystems/vcpkg.cmake
94   cmake --build .build
95   ```
96
974. Run the example, change the place holder to appropriate values:
98
99   ```bash
100   .build/quickstart [GCP PROJECT] [BUCKET NAME]
101   ```
102
103   Please use the plain bucket name. Do **not** include any `gs://` prefix, and
104   keep in mind the [bucket naming restrictions][bucket-naming-link]. For
105   example, bucket names cannot include forward slashes (`/`) or uppercase
106   letters.
107
108## Platform Specific Notes
109
110### Windows
111
112To correctly configure the MSVC runtime you should change the CMake minimum
113required version to 3.15 or add `-DCMAKE_POLICY_DEFAULT_CMP0091=NEW` to the
114CMake configuration step.
115
116[bazel-install]: https://docs.bazel.build/versions/master/install.html
117[choco-cmake-link]: https://chocolatey.org/packages/cmake
118[homebrew-cmake-link]: https://formulae.brew.sh/formula/cmake
119[cmake-download-link]: https://cmake.org/download/
120[authentication-quickstart]: https://cloud.google.com/docs/authentication/getting-started 'Authentication Getting Started'
121