Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

file not found [clang-diagnostic-error] #include "lib1.h" ^~~~~~~~ #62

Open
dshengChen opened this issue Jul 30, 2023 · 2 comments
Open

Comments

@dshengChen
Copy link

my pre-commit file look like:

fail_fast: false
repos:
-   repo: https://github.com/pre-commit/pre-commit-hooks
    rev: v4.4.0  # Use the ref you want to point at
    hooks:
    -   id: trailing-whitespace
    -   id: check-added-large-files
-   repo: https://github.com/pocc/pre-commit-hooks
    rev: master
    hooks:
      - id: clang-format
        args: [-i]
      - id: clang-tidy
      # - id: oclint
      # - id: uncrustify
      # - id: cppcheck
      # - id: cpplint

and it's a cmake c++ projects and I added set(CMAKE_EXPORT_COMPILE_COMMANDS ON) on my cmakelist.txt
and cmake generate file namedcompile_commands.json and it`s contain the file c++ src file path.

{
  "directory": "/Users/chendongsheng/github/cmake_test/build",
  "command": "/usr/bin/clang++ -I/Users/chendongsheng/github/cmake_test/lib1/. -I/Users/chendongsheng/github/cmake_test/lib2/. -g -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.3.sdk -o lib1/CMakeFiles/lib1.dir/aaa.cpp.o -c /Users/chendongsheng/github/cmake_test/lib1/aaa.cpp",
  "file": "/Users/chendongsheng/github/cmake_test/lib1/aaa.cpp"
},

but when i try to run pre-commit run --all-files

I got error like:

[WARNING] The 'rev' field of repo 'https://github.com/pocc/pre-commit-hooks' appears to be a mutable reference (moving tag / branch).  Mutable references are never updated after first install and are not supported.  See https://pre-commit.com/#using-the-latest-version-for-a-repository for more details.  Hint: `pre-commit autoupdate` often fixes this.
trim trailing whitespace.................................................Passed
check for added large files..............................................Passed
clang-format.............................................................Passed
clang-tidy...............................................................Failed
- hook id: clang-tidy
- exit code: 1

/Users/chendongsheng/github/cmake_test/app/main.cpp:1:10: error: 'lib1.h' file not found [clang-diagnostic-error]
#include "lib1.h"
         ^~~~~~~~
Error while trying to load a compilation database:
Could not auto-detect compilation database for file "lib1/aaa.cpp"
No compilation database found in /Users/chendongsheng/github/cmake_test/lib1 or any parent directory
fixed-compilation-database: Error while opening fixed database: No such file or directory
json-compilation-database: Error while opening JSON database: No such file or directory
Running without flags.
Error while trying to load a compilation database:
Could not auto-detect compilation database for file "app/main.cpp"
No compilation database found in /Users/chendongsheng/github/cmake_test/app or any parent directory
fixed-compilation-database: Error while opening fixed database: No such file or directory
json-compilation-database: Error while opening JSON database: No such file or directory
Running without flags.
1 error generated.
Error while processing /Users/chendongsheng/github/cmake_test/app/main.cpp.
Found compiler error(s).
@dshengChen
Copy link
Author

(openai) ➜  cmake_test git:(master) ✗ pre-commit --version
pre-commit 3.2.1
(openai) ➜  cmake_test git:(master) ✗ clang-tidy --version
Homebrew LLVM version 16.0.6
  Optimized build.
image

@dshengChen
Copy link
Author

My workSpace look like:

(openai) ➜  cmake_test git:(master) ✗ tree -L 1
.
├── CMakeLists.txt
├── aaa.plist
├── app
├── build
├── defaults.cfg
├── lib1
├── lib2
├── readme.md
└── tmp

and compile_commands.json is under folder build.

when I copy ./build/compiler_commands.json into ./lib1/ and ./lib2/ folder.
The problem is fixed.

so I thinkd it's shoudle because the pre-commit can't find the file compiler_commands.json.

how coulde other peopel not see this problem?
Is I miss something setting?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant