Bear is a tool that generates a compilation database for clang tooling.
The JSON compilation database is used in the clang project to provide information on how a single compilation unit is processed. With this, it is easy to re-run the compilation with alternate programs.
One way to get a compilation database is to use
cmake as the build
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON to cmake generates
compile_commands.json file into the current directory.
For non-cmake projects, use Bear. Bear generates the json file during the build process.
The concept behind Bear is to execute the original build command and
exec calls issued by the build tool. To achieve that, Bear uses the
DYLD_INSERT_LIBRARIES mechanisms provided by the dynamic
Bear has two components: the library and the binary. The library
exec methods to be used by all child processes. The
executable enables the use of the library for child processes and
writes the output file.
How to build
Bear should be quite portable on UNIX operating systems. It has been tested on FreeBSD, GNU/Linux and OS X.
- an ANSI C compiler, to compile the sources.
- cmake, to configure the build process.
- make, to run the build. The makefiles are generated by
- python is a runtime dependency. The
bearcommand is written in Python. (version >= 2.7)
Ideally, you should build Bear in a separate build directory.
cmake $BEAR_SOURCE_DIR make all make install # to install make check # to run tests make package # to make packages
You can configure the build process with passing arguments to cmake.
How to use
After installation the usage is like this:
The output file called
compile_commands.json found in current directory.
For more options you can check the man page or pass
Because Bear uses
DYLD_INSERT_LIBRARIES environment variables,
it does not append to it, but overrides it. So builds which are using these
variables might not work. (I don't know any build tool which does that, but
please let me know if you do.)
If you find a bug in this documentation or elsewhere in the program or would like to propose an improvement, please use the project's github issue tracker. Please describing the bug and where you found it. If you have a suggestion how to fix it, include that as well. Patches are also welcome.