> ## Documentation Index
> Fetch the complete documentation index at: https://site.aspect.build/llms.txt
> Use this file to discover all available pages before exploring further.

# Outline

> Bazel 104 covers C and C++ with hermetic LLVM toolchains, rules_cc, rules_foreign_cc for legacy cmake projects, and external library dependencies.

{!user.loggedIn ? (
<Tip>
<a href="https://auth.aspect.build/oauth/account/sign-up">Sign up</a> for a free Aspect account to access the full training course. Already have one? <a href="/login?redirect=%2Flearning%2Fbazel-104">Log in</a>.
</Tip>
) : null}

Given the shortcomings of alternatives like `cmake`, Bazel is a pretty great choice for C++ applications, even if you don’t need a multi-language or multi-application monorepo.

We’ll use the following tools and libraries:

* [https://registry.bazel.build/](https://registry.bazel.build/) has a bunch of C++ libraries which can be built from source within your build.
* [https://registry.bazel.build/modules/toolchains\_llvm](https://registry.bazel.build/modules/toolchains_llvm) adds a hermetic C++ toolchain to Bazel, which can include a sysroot that fully decouples build results from packages installed on the host machine. There are options for other compilers like `gcc` too.
* [https://registry.bazel.build/modules/rules\_foreign\_cc](https://registry.bazel.build/modules/rules_foreign_cc) lets you re-use legacy builds under Bazel, for example using cmake.
* [https://github.com/bazelbuild/rules\_cc](https://github.com/bazelbuild/rules_cc) is a re-implementation of Bazel’s built-in C++ rules in Starlark, Bazel’s extension language.
* [Aspect CLI](/docs/cli/overview) includes a `gazelle` command that can do some auto-generation of `BUILD` files, freeing you from some of the tedium of specifying sources and dependencies.

Before starting the course, we assume you’ve already taken [Bazel 101](/learning/bazel-101).

You can clone the [C/C++ starter template](https://github.com/aspect-starters/cpp) for a working setup to follow along.

Watch a live presentation of this course:

<iframe src="https://streamyard.com/e/jhnhf8gckvmf" width="560" height="315" frameborder="0" title="Embed recording" allowfullscreen />

## Outline

[Running a “hello world” application](/learning/bazel-104/run-hello-world)

[Link against pre-installed system libraries](/learning/bazel-104/link-against-system-libs)

[Build external dependencies from source](/learning/bazel-104/external-deps)

[Configuring the IDE or editor](/learning/bazel-104/ide)

[Testing and debugging with GoogleTest](/learning/bazel-104/test-and-debug)

[Cross-compilation to target platforms](/learning/bazel-104/cross-compile)

[Linting and Formatting](/learning/bazel-104/lint-and-format)

[BUILD file generation](/learning/bazel-104/gazelle)

### Topics we may cover in the future

* Link against external dependencies from a distro like Debian
  * apko or APT
  * RPATH in ELF header
  * point to some ruleset
* Embedding C++ code in other languages with Foreign Function Interfaces
  * Binding to a dylib vs static link into program
  * Go (cgo)
  * Python (pybind)
  * npm (gyp)
  * Java (SWIG)
* Alternative toolchains
  * musl syscall implementations (doesn’t need runtime linking)
* Sanitizers
  * Asan
  * Ubsan
  * Tsan
