Closed HansLjy closed 1 month ago
Where is the header Eigen/Dense
located in the filesystem?
Can you show a log for opening main.cc?
Thanks for the reply. Eigen/Dense
is located in /usr/local/include/eigen3/Eigen/Dense
. Below is the log for opening main.cc
:
I[09:32:56.664] Ubuntu clangd version 14.0.0-1ubuntu1.1
I[09:32:56.664] Features: linux+grpc
I[09:32:56.664] PID: 84591
I[09:32:56.665] Working directory: /home/hansljy/tmp/test
I[09:32:56.665] argv[0]: /usr/bin/clangd
I[09:32:56.665] argv[1]: -header-insertion=never
I[09:32:56.665] Starting LSP over stdin/stdout
I[09:32:56.665] <-- initialize(0)
I[09:32:56.665] --> reply:initialize(0) 0 ms
I[09:32:56.666] <-- initialized
I[09:32:56.668] <-- textDocument/didOpen
I[09:32:56.669] --> textDocument/publishDiagnostics
I[09:32:56.669] Loaded compilation database from /home/hansljy/tmp/test/build/compile_commands.json
I[09:32:56.669] --> window/workDoneProgress/create(0)
I[09:32:56.669] ASTWorker building file /home/hansljy/tmp/test/main.cc version 1 with command
[/home/hansljy/tmp/test/build]
/usr/bin/c++ --driver-mode=g++ -isystem /usr/local/include/eigen3 -o CMakeFiles/main1.dir/main.cc.o -c -std=c++17 -resource-dir=/usr/lib/llvm-14/lib/clang/14.0.0 -- /home/hansljy/tmp/test/main.cc
I[09:32:56.669] Enqueueing 2 commands for indexing
I[09:32:56.669] <-- reply(0)
I[09:32:56.669] --> $/progress
I[09:32:56.669] --> $/progress
I[09:32:56.670] --> textDocument/clangd.fileStatus
I[09:32:56.729] <-- textDocument/documentLink(1)
I[09:32:56.730] <-- clangd/inlayHints(2)
I[09:32:56.788] --> $/progress
I[09:32:56.788] --> $/progress
I[09:32:56.840] <-- textDocument/codeAction(3)
I[09:32:56.840] <-- $/cancelRequest
I[09:32:56.840] <-- textDocument/codeAction(4)
I[09:32:56.840] <-- $/cancelRequest
I[09:32:56.840] <-- textDocument/codeAction(5)
I[09:32:56.840] <-- $/setTrace
I[09:32:56.840] unhandled notification $/setTrace
I[09:32:56.850] <-- $/setTrace
I[09:32:56.850] unhandled notification $/setTrace
I[09:32:56.902] <-- $/setTrace
I[09:32:56.902] unhandled notification $/setTrace
I[09:32:57.060] <-- textDocument/documentSymbol(6)
I[09:32:57.060] <-- $/cancelRequest
I[09:32:57.060] <-- $/cancelRequest
I[09:32:57.060] <-- textDocument/codeAction(7)
I[09:32:57.083] <-- textDocument/documentLink(8)
I[09:32:57.351] --> workspace/semanticTokens/refresh(1)
I[09:32:57.352] <-- reply(1)
I[09:32:57.357] --> textDocument/publishDiagnostics
I[09:32:57.357] --> reply:textDocument/documentLink(1) 627 ms, error: Task was cancelled.
I[09:32:57.357] --> reply:clangd/inlayHints(2) 627 ms
I[09:32:57.357] --> reply:textDocument/codeAction(3) 517 ms, error: Task was cancelled.
I[09:32:57.357] --> reply:textDocument/codeAction(4) 517 ms, error: Task was cancelled.
I[09:32:57.357] --> reply:textDocument/codeAction(5) 517 ms, error: Task was cancelled.
I[09:32:57.357] --> reply:textDocument/documentSymbol(6) 296 ms
I[09:32:57.357] --> reply:textDocument/codeAction(7) 296 ms
I[09:32:57.357] --> reply:textDocument/documentLink(8) 273 ms
I[09:32:57.357] --> textDocument/clangd.fileStatus
[Error - 09:32:57] Request textDocument/documentLink failed.
[object Object]
[Error - 09:32:57] Request textDocument/codeAction failed.
[object Object]
[Error - 09:32:57] Request textDocument/codeAction failed.
[object Object]
[Error - 09:32:57] Request textDocument/codeAction failed.
[object Object]
I[09:32:58.525] <-- clangd/inlayHints(9)
I[09:32:58.525] --> reply:clangd/inlayHints(9) 0 ms
I[09:32:58.525] --> textDocument/clangd.fileStatus
I[09:33:00.548] <-- textDocument/codeAction(10)
I[09:33:00.548] --> reply:textDocument/codeAction(10) 0 ms
I[09:33:00.548] --> textDocument/clangd.fileStatus
I[09:33:00.548] <-- textDocument/documentSymbol(11)
I[09:33:00.549] --> reply:textDocument/documentSymbol(11) 0 ms
I[09:33:00.549] --> textDocument/clangd.fileStatus
Well, it looks like the generated compile command for main.cc
contains -isystem /usr/local/include/eigen3
, and the one for main.cu
does not.
From the log, for main.cc:
I[09:32:56.669] ASTWorker building file /home/hansljy/tmp/test/main.cc version 1 with command [/home/hansljy/tmp/test/build] /usr/bin/c++ --driver-mode=g++ -isystem /usr/local/include/eigen3 -o CMakeFiles/main1.dir/main.cc.o -c -std=c++17 -resource-dir=/usr/lib/llvm-14/lib/clang/14.0.0 -- /home/hansljy/tmp/test/main.cc
and for main.cu:
I[11:20:36.026] ASTWorker building file /home/hansljy/tmp/test/main.cu version 1 with command [/home/hansljy/tmp/test/build] /usr/local/cuda-11.8/bin/nvcc -forward-unknown-to-host-compiler --options-file --generate-code=arch=compute_86,code=[compute_86,sm_86] -c -std=c++17 -resource-dir=/usr/lib/llvm-14/lib/clang/14.0.0 -- /home/hansljy/tmp/test/main.cu
It's the absence of this flag that's causing clangd to be unable to resolve the Eigen/Dense
include.
Seems reasonable. But how can I tell clangd to add this flag? Do I need to modify CMakeLists.txt
manually so that it generates the correct compile_commands.json
?
Assuming the flag is indeed missing from compile_commands.json
, the options are:
compile_commands.json
to contain the flag. I'm not really in a position to give specific advice here as this is more a question about the tool that generates compile_commands.json
(CMake in this case)..clangd
config file to add the flag, with something like:
CompileFlags:
Add: [-isystem, /usr/local/include/eigen3]
Thanks for the advice. I found a solution on the cmake forum(the last reply): simply add
set(CMAKE_CUDA_USE_RESPONSE_FILE_FOR_INCLUDES 0)
set(CMAKE_CUDA_USE_RESPONSE_FILE_FOR_LIBRARIES 0)
set(CMAKE_CUDA_USE_RESPONSE_FILE_FOR_OBJECTS 0)
to the top-level CMakeLists.txt
. I am not sure about the side effects of this, but it solves my problem.
I am not sure whether this is a problem of clangd or vscode-clangd. This is a minimum (non-)working example:
File structure:
CMakeLists.txt
:main.cc
:main.cu
:Both targets (
main1
andmain2
) can compile successfully. However, vscode shows the following error formain.cu
:On the contrary, there is no error for
main.cc
, so I suppose it has something to do with CUDA files.The following is the log of
clangd
copied from theOutput
:System Info
I use Ubuntu 22.04. The version for clangd is 14.0.0.