How to Install Abseil C++: CMake, Bazel, and Conan Setup Guide

Abseil C++ can be integrated into your project using CMake via add_subdirectory or find_package, Bazel through http_archive in your WORKSPACE file, or Conan using the provided conanfile.py, with system package managers offering pre-built alternatives for Linux distributions.

The abseil/abseil-cpp repository provides several installation methods to accommodate different build systems and workflows. Whether you prefer CMake's widespread compatibility, Bazel's native integration, or Conan's package management, the library offers documented paths in CMake/README.md, README.md, and conanfile.py for each approach.

CMake is the most portable option for incorporating Abseil into existing C++ projects. The CMakeLists.txt at the repository root provides targets that can be consumed either as a subdirectory or as an installed package.

Adding Abseil as a Subdirectory

Clone the repository and include it directly in your build tree. This method avoids system-wide installation and ensures ABI compatibility.

git clone https://github.com/abseil/abseil-cpp.git
cd abseil-cpp

In your project's CMakeLists.txt, add the Abseil source tree and link the specific targets you need:

cmake_minimum_required(VERSION 3.16)
project(my_project)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

add_subdirectory(path/to/abseil-cpp)

add_executable(my_app src/main.cpp)
target_link_libraries(my_app
    absl::base
    absl::strings
    absl::synchronization)

Installing Abseil System-Wide

For environments where multiple projects share the same Abseil installation, enable the install step using the ABSL_ENABLE_INSTALL option defined in CMakeLists.txt.

cmake -B build -S . -DABSL_ENABLE_INSTALL=ON
cmake --build build
cmake --install build  # Installs to /usr/local by default

After installation, downstream projects can locate the library using standard CMake patterns:

find_package(absl REQUIRED)
target_link_libraries(my_target absl::base absl::strings)

Bazel Installation (Official Build System)

Bazel is the official build system for Abseil and provides the fastest integration for Google-centric toolchains. Add the following to your WORKSPACE file to fetch the repository:

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
    name = "abseil_cpp",
    urls = ["https://github.com/abseil/abseil-cpp/archive/refs/heads/master.zip"],
    strip_prefix = "abseil-cpp-master",
    sha256 = "<computed-sha256>",
)

In your BUILD files, declare dependencies on specific Abseil modules:

cc_binary(
    name = "my_binary",
    srcs = ["main.cc"],
    deps = [
        "@abseil_cpp//absl:base",
        "@abseil_cpp//absl:strings",
        "@abseil_cpp//absl:synchronization",
    ],
)

Run your build with:

bazel build //:my_binary

The ci/ directory contains reference scripts demonstrating Bazel builds across various platforms.

Conan Installation (Package Manager)

For projects already using Conan, the repository includes a conanfile.py recipe for packaging Abseil.

Create the package from the repository root:

conan create . abseil/2024.0

Consume it in your conanfile.txt:

[requires]
abseil/2024.0

[generators]
cmake

Then install dependencies and proceed with your standard CMake workflow:

conan install .
cmake -B build .
cmake --build build

System Package Managers

Some Linux distributions ship pre-built Abseil packages. For example, Debian and Ubuntu users can install via:

sudo apt install libabsl-dev

This method provides the quickest installation but may lag behind the upstream repository in version availability.

Summary

  • CMake offers two paths: add_subdirectory for embedded builds or ABSL_ENABLE_INSTALL with find_package for system-wide installation, documented in CMake/README.md.
  • Bazel uses http_archive in your WORKSPACE file and deps in BUILD files, providing the most native integration as described in README.md.
  • Conan leverages the provided conanfile.py to create versioned packages consumable by any CMake-based project.
  • System packages like libabsl-dev provide immediate availability but potentially older versions.

Frequently Asked Questions

Can I install Abseil C++ using apt or yum?

Yes. Debian and Ubuntu provide libabsl-dev through the apt repository. Red Hat-based distributions may package Abseil in EPEL or similar repositories. However, distribution packages often trail the GitHub repository by several releases, so check the version against your requirements.

What is the minimum C++ standard required for Abseil?

Abseil requires C++17 or later. When using CMake, ensure you set CMAKE_CXX_STANDARD to 17 or higher and enable CMAKE_CXX_STANDARD_REQUIRED to enforce compliance, as the library uses modern C++ features extensively.

Abseil provides fine-grained targets following the absl:: namespace convention. In your target_link_libraries() call, specify only the modules you need, such as absl::base, absl::strings, absl::synchronization, or absl::flat_hash_map. This selective linking reduces binary size and dependency overhead compared to linking a monolithic library.

Is Bazel required to use Abseil C++?

No. While Bazel is the official build system used internally at Google and referenced in the quick-start documentation, CMake is fully supported and widely used in the open-source community. The CMakeLists.txt and CMake/README.md files provide comprehensive instructions for non-Bazel environments.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →