LinuxCommandLibrary

bear

Generate compilation database for clang tooling

TLDR

Generate compilation database

$ bear -- make
copy
Append to existing database
$ bear --append -- make clean all
copy
Custom output file
$ bear --output [compile_commands.json] -- ninja
copy

SYNOPSIS

bear [options] -- build-command

DESCRIPTION

bear (Build EAR) generates a compilation database (compile_commands.json) by intercepting compiler calls during a build. This database enables tools like clangd, clang-tidy, and IDEs to understand the project structure without custom configuration.
The tool works with any build system by recording actual compiler invocations.

PARAMETERS

--append, -a

Append to existing compilation database
--output file, -o file
Output file (default: compile_commands.json)
--force-preload
Force library preload method
--force-wrapper
Force compiler wrapper method
--verbose, -v
Verbose output

WORKFLOW

$ # With Make
bear -- make

# With CMake/Ninja
bear -- ninja

# Clean build
bear -- make clean all

# Append incremental build
bear --append -- make module
copy

FEATURES

- Build system agnostic
- Intercepts compiler calls
- Supports parallel builds
- Works with make, ninja, etc.
- No build system modification needed

COMPILATION DATABASE

Generated compile_commands.json format:

$ [
  {
    "directory": "/path/to/project",
    "command": "gcc -c file.c -o file.o",
    "file": "file.c"
  }
]
copy

CAVEATS

Requires running full build. May not capture all compilation units if cached. Some build systems have native support (CMake: -DCMAKEEXPORTCOMPILE_COMMANDS=ON). Different interception methods on different platforms.

HISTORY

bear was created by László Nagy around 2012 to generate compilation databases for C/C++ projects using any build system.

SEE ALSO

compiledb(1), cmake(1), clangd(1)

> TERMINAL_GEAR

Curated for the Linux community

Copied to clipboard

> TERMINAL_GEAR

Curated for the Linux community