Setting up a C++ development environment (original) (raw)

This tutorial shows how to prepare your local machine forC++development, including developing C++ apps that run on Google Cloud.

If you already have a development environment set up, seeC++ and Google Cloudto get an overview of how to run C++ apps on Google Cloud.

Objectives

Installing C++

C++'s installation instructions vary by operating system. Follow the guide for the operating system you're running in your development environment, macOS, Windows, or Linux.

macOS

  1. You can get a C++ compiler by installingXcode's command-line tools.
xcode-select --install  
  1. After the installation is complete, verify that your compiler is available as c++:
c++ --version  

Windows

  1. To install a C++ compiler in a Windows environment, download the Microsoft's "Visual Studio" from theVisual Studio website. This will download a full IDE, including an editor, debugger and build systems.
  2. To access your C++ compiler follow the C++ section in Visual Studio'sGetting Startedguide.

Linux

Most (if not all) Linux distributions include GCCas their primary C++ compiler. Many Linux distributions also includeCLangas an alternative C++ compiler. The C++ client libraries support both.

  1. To install C++ in a Linux environment, install the appropriate packages for your distribution. For Debian and Ubuntu, this package isg++.
    Install these packages using the following commands:
sudo apt update  
sudo apt install g++  
  1. After the installations are complete, verify that you have g++installed:
g++ --version  

Install a C++ Build System compatible with Google Cloud

To use C++ effectively you will want a build system and package manager that supports the Cloud Client Libraries for C++. The client libraries support multiple such build systems and package managers.

Install an editor

There are many editors and IDEswith C++ support. Pick one that fits your needs. Consider these features as you make your selection:

Install the Google Cloud CLI

The Google Cloud CLIis a set of tools for Google Cloud. It contains thegcloudand bqcommand-line tools used to access Compute Engine, Cloud Storage, BigQuery, and other services from the command line. You can run these tools interactively or in your automated scripts.

Install the Cloud Client Libraries for C++

The Cloud Client Libraries for C++is the idiomatic way for C++ developers to integrate with Google Cloud services, such as Spanner and Cloud Storage.

For example, to install the package for an individual API, such as the Cloud Storage API, do the following:

CMake with vcpkg

  1. Add google-cloud-cpp as dependency to your vcpkg.json file:
  2. Edit your CMakeLists.txt file to require the library
  3. Add this dependency to your targets
  4. Configure CMake using the vcpkg toolchain. This will automatically download, and compile google-cloud-cpp and its dependencies.
cmake -S . -B [build directory] \  
    -DCMAKE_TOOLCHAIN_FILE=[vcpkg location]/scripts/buildsystems/vcpkg.cmake  

CMake with Conda

  1. Install the dependencies using Conda:
  2. Edit your CMakeLists.txt file to require the library
  3. Add this dependency to your targets
  4. Configure CMake within your Conda environment..
cmake -S . -B [build directory]  

Bazel

  1. In your WORKSPACE file add the follow command to download the Cloud Client Libraries for C++ source code:
  2. In your WORKSPACE file call the Starlark functions to load recursive dependencies:
  3. In your BUILD file use the Cloud Storage library:

Set up authentication

To use the Cloud Client Libraries in a local development environment, set up Application Default Credentials.

If you're using a local shell, then create local authentication credentials for your user account:

gcloud auth application-default login

You don't need to do this if you're using Cloud Shell.

If an authentication error is returned, and you are using an external identity provider (IdP), confirm that you have signed in to the gcloud CLI with your federated identity.

For more information, seeAuthenticate for using client libraries.

What's next