bear
Generate compilation database for clang tooling
TLDR
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. From version 3 onward, the build command must be separated from bear's own options by a `--`; older 2.4.x packages omit it.
PARAMETERS
-o file, --output file
Output file (default: compile_commands.json)-a, --append
Append results to an existing database instead of overwriting it-c file, --config file
Read settings (output formatting, compiler/source filters) from a configuration file-h, --help
Print help information-V, --version
Print version information
WORKFLOW
bear -- make
# With CMake/Ninja
bear -- ninja
# Clean build
bear -- make clean all
# Append incremental build
bear --append -- make module
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"
}
]
INSTALL
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 (rizsotto) around 2012 to generate compilation databases for C/C++ projects using any build system. Version 3 introduced the `--` separator syntax, and version 4 rewrote the tool in Rust.
