linter-clang
linter-clang copied to clipboard
Linter issues when including headers in subdirectories
Considering the following directory structure:
.
|-- CMakeLists.txt
|-- Main.cpp
|-- compile_commands.json
|-- FooLib
| |-- CMakeLists.txt
| |-- FooLib.h
| `-- FooLib.cpp
|-- BarLib
| |-- CMakeLists.txt
| |-- BarLib.h
| `-- BarLib.cpp
If BarLib.h
contains #include "FooLib.h"
, and the flag -I/absolute/path/to/FooLib
is present in its target entry in compile_commands.json
, this atom Atom package generates an error in the BarLib.h
file, not finding the FooLib.h
header.
Main.cpp
instead works as expected, only the subfolders suffer from this problem.
It should work if you rename build_commands.json
to compile_commands.json
as stated in the readme.
Sorry, it was a typo. Its name is already compile_commands.json
, I mixed its name and the folder it was inside (build
), pardon. I edited the first message accordingly.
Okay, attempting to reproduce locally.
Hmmm, looks like clang-flags
isn't finding anything for that file, could you possibly upload an archive or create a gist of this to make sure I haven't screwed up setting this up?
I uploaded here an archive with a minimal example. You'll also find the compile_commands.json
that was generated by CMake.
Commands:
mkdir build
cd build
cmake .. -DCMAKE_EXPORT_COMPILE_COMMANDS=1
cp compile_commands.json ..
make
@Arcanemagus I updated my setup to clang4
, and the problem still persists. I didn't dig much into your code, but so far my limited knowledge about all the clang
features didn't allow me to get a working static analyzer in the tarball I uploaded with compile_commands.json
support if not executing clang-check
or clang-tidy
. These two tools provide the -p
option, clang --analyze
doesn't.
I have the same issue. Has anyone resolved it?
compile_commands.json
only provides information on the compiler flags/options for source files, not headers as headers aren't processed into translation units, only the source files that include them. This method doesn't make sense to work with header files. I would recommend using the .clang-complete
option for global includes.