linter-clang icon indicating copy to clipboard operation
linter-clang copied to clipboard

Linter issues when including headers in subdirectories

Open diegoferigo opened this issue 7 years ago • 8 comments

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.

diegoferigo avatar Apr 04 '17 12:04 diegoferigo

It should work if you rename build_commands.json to compile_commands.json as stated in the readme.

Arcanemagus avatar Apr 04 '17 15:04 Arcanemagus

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.

diegoferigo avatar Apr 04 '17 15:04 diegoferigo

Okay, attempting to reproduce locally.

Arcanemagus avatar Apr 04 '17 16:04 Arcanemagus

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?

Arcanemagus avatar Apr 04 '17 16:04 Arcanemagus

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

diegoferigo avatar Apr 05 '17 06:04 diegoferigo

@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.

diegoferigo avatar Jul 13 '17 08:07 diegoferigo

I have the same issue. Has anyone resolved it?

Jazzz42 avatar Sep 30 '18 22:09 Jazzz42

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.

nick-prat avatar Oct 02 '18 17:10 nick-prat