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

clangd doesn't find include paths #717

Open
thewh1teagle opened this issue Nov 8, 2024 · 9 comments
Open

clangd doesn't find include paths #717

thewh1teagle opened this issue Nov 8, 2024 · 9 comments
Labels
bug Something isn't working

Comments

@thewh1teagle
Copy link

thewh1teagle commented Nov 8, 2024

Clang doesn't format the files and throw errors that it failed to find imports from external libraries (I use cmake)

#include "sherpa-onnx/c-api/c-api.h"
'sherpa-onnx/c-api/c-api.h' file not foundclang(pp_file_not_found)

the headers available in build/_deps/sherpa-src/include.

The project compiles successfuly with cmake. I also tried to produce compile_commands.json and place it in root folder. it didn't helped.

https://github.com/thewh1teagle/loud.cpp

Also clangd says there's too many errors and it doesn't do anything except for showing the error. no formatting etc.

Logs
Please attach the clangd log from the "Output" window if you can.
If possible, run with --log=verbose - note that the logs will include the contents of open files!

I[16:27:21.492] <-- shutdown(46)
I[16:27:21.492] --> reply:shutdown(46) 0 ms
I[16:27:21.492] <-- exit
I[16:27:21.492] LSP finished, exiting with status 0
I[16:27:21.580] Homebrew clangd version 18.1.8
I[16:27:21.582] Features: mac+xpc
I[16:27:21.582] PID: 73143
I[16:27:21.582] Working directory: /Volumes/Internal/loud.cpp
I[16:27:21.582] argv[0]: /opt/homebrew/opt/llvm/bin/clangd
I[16:27:21.582] argv[1]: --compile-commands-dir=/Volumes/Internal/loud.cpp/build
I[16:27:21.582] argv[2]: --completion-style=detailed
I[16:27:21.582] argv[3]: --header-insertion=never
I[16:27:21.582] Starting LSP over stdin/stdout
I[16:27:21.583] <-- initialize(0)
I[16:27:21.594] --> reply:initialize(0) 11 ms
I[16:27:21.594] <-- initialized
I[16:27:21.597] <-- textDocument/didOpen
I[16:27:21.599] <-- textDocument/didOpen
I[16:27:21.599] <-- textDocument/didOpen
I[16:27:21.600] <-- textDocument/didOpen
I[16:27:21.601] Loaded compilation database from /Volumes/Internal/loud.cpp/build/compile_commands.json
I[16:27:21.602] --> window/workDoneProgress/create(0)
I[16:27:21.602] Enqueueing 11 commands for indexing
I[16:27:21.602] <-- reply(0)
I[16:27:21.602] ASTWorker building file /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/vector version 1 with command inferred from /Volumes/Internal/loud.cpp/build/_deps/whisper-src/ggml/src/ggml-aarch64.c
[/Volumes/Internal/loud.cpp/build/_deps/whisper-build/ggml/src]
/usr/bin/clang -DACCELERATE_LAPACK_ILP64 -DACCELERATE_NEW_LAPACK -DGGML_METAL_EMBED_LIBRARY -DGGML_SCHED_MAX_COPIES=4 -DGGML_USE_ACCELERATE -DGGML_USE_BLAS -DGGML_USE_METAL -DGGML_USE_OPENMP -D_DARWIN_C_SOURCE -D_XOPEN_SOURCE=600 -I/Volumes/Internal/loud.cpp/build/_deps/whisper-src/ggml/src/../include -I/Volumes/Internal/loud.cpp/build/_deps/whisper-src/ggml/src/. -F/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.5.sdk/System/Library/Frameworks -isystem /opt/homebrew/opt/libomp/include -g -arch arm64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.5.sdk -Wshadow -Wstrict-prototypes -Wpointer-arith -Wmissing-prototypes -Werror=implicit-int -Werror=implicit-function-declaration -Wall -Wextra -Wpedantic -Wcast-qual -Wno-unused-function -Wunreachable-code-break -Wunreachable-code-return -Wdouble-promotion -Xclang -fopenmp -c -x c-header -std=gnu11 -resource-dir=/opt/homebrew/Cellar/llvm/18.1.8/lib/clang/18 -- /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/vector
I[16:27:21.602] --> $/progress
I[16:27:21.602] ASTWorker building file /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/iostream version 1 with command inferred from /Volumes/Internal/loud.cpp/build/_deps/whisper-src/ggml/src/ggml-aarch64.c
[/Volumes/Internal/loud.cpp/build/_deps/whisper-build/ggml/src]
/usr/bin/clang -DACCELERATE_LAPACK_ILP64 -DACCELERATE_NEW_LAPACK -DGGML_METAL_EMBED_LIBRARY -DGGML_SCHED_MAX_COPIES=4 -DGGML_USE_ACCELERATE -DGGML_USE_BLAS -DGGML_USE_METAL -DGGML_USE_OPENMP -D_DARWIN_C_SOURCE -D_XOPEN_SOURCE=600 -I/Volumes/Internal/loud.cpp/build/_deps/whisper-src/ggml/src/../include -I/Volumes/Internal/loud.cpp/build/_deps/whisper-src/ggml/src/. -F/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.5.sdk/System/Library/Frameworks -isystem /opt/homebrew/opt/libomp/include -g -arch arm64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.5.sdk -Wshadow -Wstrict-prototypes -Wpointer-arith -Wmissing-prototypes -Werror=implicit-int -Werror=implicit-function-declaration -Wall -Wextra -Wpedantic -Wcast-qual -Wno-unused-function -Wunreachable-code-break -Wunreachable-code-return -Wdouble-promotion -Xclang -fopenmp -c -x c-header -std=gnu11 -resource-dir=/opt/homebrew/Cellar/llvm/18.1.8/lib/clang/18 -- /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/iostream
I[16:27:21.602] --> $/progress
I[16:27:21.602] ASTWorker building file /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/stdio.h version 1 with command inferred from /Volumes/Internal/loud.cpp/build/_deps/whisper-src/ggml/src/ggml-aarch64.c
[/Volumes/Internal/loud.cpp/build/_deps/whisper-build/ggml/src]
/usr/bin/clang -DACCELERATE_LAPACK_ILP64 -DACCELERATE_NEW_LAPACK -DGGML_METAL_EMBED_LIBRARY -DGGML_SCHED_MAX_COPIES=4 -DGGML_USE_ACCELERATE -DGGML_USE_BLAS -DGGML_USE_METAL -DGGML_USE_OPENMP -D_DARWIN_C_SOURCE -D_XOPEN_SOURCE=600 -I/Volumes/Internal/loud.cpp/build/_deps/whisper-src/ggml/src/../include -I/Volumes/Internal/loud.cpp/build/_deps/whisper-src/ggml/src/. -F/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.5.sdk/System/Library/Frameworks -isystem /opt/homebrew/opt/libomp/include -g -arch arm64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.5.sdk -Wshadow -Wstrict-prototypes -Wpointer-arith -Wmissing-prototypes -Werror=implicit-int -Werror=implicit-function-declaration -Wall -Wextra -Wpedantic -Wcast-qual -Wno-unused-function -Wunreachable-code-break -Wunreachable-code-return -Wdouble-promotion -Xclang -fopenmp -c -x c-header -std=gnu11 -resource-dir=/opt/homebrew/Cellar/llvm/18.1.8/lib/clang/18 -- /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/stdio.h
I[16:27:21.602] ASTWorker building file /Volumes/Internal/loud.cpp/src/main.cpp version 33 with command inferred from /Volumes/Internal/loud.cpp/build/_deps/whisper-src/ggml/src/ggml-backend.cpp
[/Volumes/Internal/loud.cpp/build/_deps/whisper-build/ggml/src]
/usr/bin/clang++ --driver-mode=g++ -DACCELERATE_LAPACK_ILP64 -DACCELERATE_NEW_LAPACK -DGGML_METAL_EMBED_LIBRARY -DGGML_SCHED_MAX_COPIES=4 -DGGML_USE_ACCELERATE -DGGML_USE_BLAS -DGGML_USE_METAL -DGGML_USE_OPENMP -D_DARWIN_C_SOURCE -D_XOPEN_SOURCE=600 -I/Volumes/Internal/loud.cpp/build/_deps/whisper-src/ggml/src/../include -I/Volumes/Internal/loud.cpp/build/_deps/whisper-src/ggml/src/. -F/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.5.sdk/System/Library/Frameworks -isystem /opt/homebrew/opt/libomp/include -g -arch arm64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.5.sdk -Wmissing-declarations -Wmissing-noreturn -Wall -Wextra -Wpedantic -Wcast-qual -Wno-unused-function -Wunreachable-code-break -Wunreachable-code-return -Wmissing-prototypes -Wextra-semi -Xclang -fopenmp -c -std=gnu++11 -resource-dir=/opt/homebrew/Cellar/llvm/18.1.8/lib/clang/18 -- /Volumes/Internal/loud.cpp/src/main.cpp
I[16:27:21.603] --> textDocument/clangd.fileStatus
I[16:27:21.603] --> textDocument/clangd.fileStatus
I[16:27:21.603] --> textDocument/clangd.fileStatus
I[16:27:21.604] --> textDocument/clangd.fileStatus
I[16:27:21.614] <-- textDocument/documentSymbol(1)
I[16:27:21.614] <-- textDocument/codeAction(2)
I[16:27:21.644] <-- textDocument/documentLink(3)
I[16:27:21.644] <-- textDocument/inlayHint(4)
I[16:27:21.690] Built preamble of size 1030776 for file /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/stdio.h version 1 in 0.09 seconds
I[16:27:21.690] --> workspace/semanticTokens/refresh(1)
I[16:27:21.690] Indexing c17 standard library in the context of /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/stdio.h
I[16:27:21.692] <-- reply(1)
I[16:27:21.692] <-- textDocument/semanticTokens/full(5)
I[16:27:21.704] --> textDocument/publishDiagnostics
I[16:27:21.704] --> textDocument/inactiveRegions
I[16:27:21.704] --> textDocument/clangd.fileStatus
I[16:27:21.748] Built preamble of size 1367316 for file /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/vector version 1 in 0.14 seconds
I[16:27:21.748] --> workspace/semanticTokens/refresh(2)
I[16:27:21.749] <-- reply(2)
I[16:27:21.764] Indexed c17 standard library: 3636 symbols, 38 filtered
I[16:27:21.811] <-- textDocument/foldingRange(6)
I[16:27:21.812] --> reply:textDocument/foldingRange(6) 0 ms
I[16:27:21.873] Built preamble of size 1995712 for file /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/iostream version 1 in 0.27 seconds
I[16:27:21.873] --> workspace/semanticTokens/refresh(3)
I[16:27:21.877] <-- reply(3)
I[16:27:21.905] --> textDocument/publishDiagnostics
I[16:27:21.905] --> textDocument/publishDiagnostics
I[16:27:21.906] --> textDocument/inactiveRegions
I[16:27:21.906] --> textDocument/clangd.fileStatus
I[16:27:21.908] --> textDocument/inactiveRegions
I[16:27:21.908] --> textDocument/clangd.fileStatus
I[16:27:21.911] <-- textDocument/documentSymbol(7)
I[16:27:22.046] Built preamble of size 6797848 for file /Volumes/Internal/loud.cpp/src/main.cpp version 33 in 0.44 seconds
I[16:27:22.047] --> workspace/semanticTokens/refresh(4)
I[16:27:22.047] Indexing c++11 standard library in the context of /Volumes/Internal/loud.cpp/src/main.cpp
I[16:27:22.047] <-- reply(4)
E[16:27:22.113] IncludeCleaner: Failed to get an entry for resolved path : No such file or directory
E[16:27:22.113] IncludeCleaner: Failed to get an entry for resolved path : No such file or directory
E[16:27:22.113] IncludeCleaner: Failed to get an entry for resolved path : No such file or directory
I[16:27:22.114] --> textDocument/publishDiagnostics
I[16:27:22.114] --> textDocument/inactiveRegions
I[16:27:22.115] --> reply:textDocument/documentSymbol(1) 501 ms
I[16:27:22.115] --> reply:textDocument/codeAction(2) 501 ms
I[16:27:22.115] --> reply:textDocument/documentLink(3) 470 ms
I[16:27:22.115] --> reply:textDocument/inlayHint(4) 470 ms
I[16:27:22.115] --> reply:textDocument/semanticTokens/full(5) 422 ms
I[16:27:22.115] --> reply:textDocument/documentSymbol(7) 204 ms
I[16:27:22.115] --> textDocument/clangd.fileStatus
I[16:27:22.374] <-- textDocument/codeAction(8)
I[16:27:22.375] --> reply:textDocument/codeAction(8) 0 ms
I[16:27:22.375] --> textDocument/clangd.fileStatus
I[16:27:22.506] --> $/progress
I[16:27:22.506] --> $/progress
I[16:27:22.558] <-- textDocument/semanticTokens/full/delta(9)
I[16:27:22.558] --> reply:textDocument/semanticTokens/full/delta(9) 0 ms
I[16:27:22.558] --> textDocument/clangd.fileStatus
I[16:27:22.790] Indexed c++11 standard library: 9460 symbols, 2322 filtered

System information
Clangd version (from the log, or clangd --version):

Apple clangd version 15.0.0 (clang-1500.3.9.4)
Features: mac+xpc
Platform: x86_64-apple-darwin23.5.0; target=arm64-apple-darwin23.5.0

clangd extension version: v0.1.29
Operating system: macos

@thewh1teagle thewh1teagle added the bug Something isn't working label Nov 8, 2024
@JVApen
Copy link
Contributor

JVApen commented Nov 10, 2024

This bug actually belongs on clangd/clangd
Regardless, do you have the entry of the compile_commands.json for that file?

@HighCommander4
Copy link
Contributor

Also, could you attach logs taken with --log=verbose please?

@thewh1teagle
Copy link
Author

Regardless, do you have the entry of the compile_commands.json for that file?

With compile_commands.json it works well. but I have another project that I can't produce compile_commands.json. I need to specify the path. can't we specify additional includes path in settings.json?
I tried, but it didn't worked.

@HighCommander4
Copy link
Contributor

I have another project that I can't produce compile_commands.json. I need to specify the path. can't we specify additional includes path in settings.json?

Not in settings.json, but clangd has a config file (.clangd in the project directory) where you can specify includes, for example:

CompileFlags:
  Add: [-I/some/include/path, -I/another/include/path]

@thewh1teagle
Copy link
Author

Not in settings.json, but clangd has a config file (.clangd in the project directory) where you can specify includes, for example:

Does it supports relative path so it will work for others that uses the project in vscode?

@HighCommander4
Copy link
Contributor

Not in settings.json, but clangd has a config file (.clangd in the project directory) where you can specify includes, for example:

Does it supports relative path so it will work for others that uses the project in vscode?

Sort of. You can use a relative path, but the path will be interpreted relative to the working directory in which the compile command runs, which is usually the directory containing the source file. So this tends not to be very useful unless the source files are all in one directory. (There is an open issue about this: clangd/clangd#1038.)

So for this kind of use case, a compile_commands.json file generated after the project is checked out (for example by running cmake) tends to work better.

@thewh1teagle
Copy link
Author

Sort of. You can use a relative path, but the path will be interpreted relative to the working directory in which the compile command runs, which is usually the directory containing the source file. So this tends not to be very useful unless the source files are all in one directory. (There is an open issue about this: clangd/clangd#1038.)

So for this kind of use case, a compile_commands.json file generated after the project is checked out (for example by running cmake) tends to work better.

I'll see if there's some way I still can use compile_commands.
So I understand that I need either specify absolute paths in .clangd or produce compile_commands.
It would be useful if we can use relative paths which are relative to project root

@JVApen
Copy link
Contributor

JVApen commented Nov 29, 2024

I've encountered a similar problem where I have some dynamic info into the config file. I've added a task that runs on opening the project directory. This takes a template and replaces some placeholders including the current directory.

I know it is not ideal, though it works as workaround.

@facundopires
Copy link

facundopires commented Jan 9, 2025

Add this to your settings.json:

    "clangd.fallbackFlags": [
        "-I includepath"
    ]

{3BA8880C-81C7-4B99-9E92-9D4BDAC9C7EB}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants