I am running clang-tidy
on a bazel project. I have compile_commands.json
generated with what appears to be valid commands.
I am running clang-tidy
as so:
clang-tidy -p /path/to/compile_commands.json /path/tocpp/file.cpp
The error comes from not being able to include a header file. This is a transitive include.
I also ran the particular compilation command from compile_commands.json
and verified that file.cpp
can be compiled with the original toolchain (it is RHEL GCC).
What might I be missing? Is it possible that clang-tidy
isn't honoring the compilation commands? I tried running the same command above without -p /path/to/compile_commands.json
and I am seeing the same error.
Much appreciated!
compile_commands.json
itself).-p
option and I get the same result. Removing compile_commands.json
produces a different error. This all indicates that it manages to read the comp db (when it is present), but clang fails to find the header needed for that particular target.To answer this briefly, the problem wasn't to do with clang-tidy
not being able to find the compile_commands.json
database.
I did a few experiments by manually running the compile command for the particular .cpp
and it was compiling with no errors. Re-ran the same command with -v
(gcc
), which lists all the dirs the compiler searches for includes. One of those contained the missing header and this was not part of compile_commands.json
...
So all in all, I had to make an update to the tool that generates compile_commands.json
. Note this isn't native, as you might have with cmake
as a build system.
Sharing my steps, so hopefully someone else dealing with a similar issue have a few more things to try out :)