Closed chatchoi closed 2 months ago
I'm on Windows. I originally use llvm-mingw as the default compiler, but some projects only support GCC. I finally decided to use niXman's GCC and llvm-mingw in parallel, which niXman's GCC has higher precedent in
PATH
so it will be picked up before llvm-mingw. I still use the clangd from llvm-mingw, though. The problem is even if I have acompiler_commands.json
generated by CMake, clangd still struggled to find standard library headers (of GCC). I examined thecompiler_commands.json
generated by CMake and I found it doesn't include the path to the standard library headers (why should it?). I hacked it to include the path to the standard library headers (of GCC) like the guy on #444, but it doesn't help. It will always struggled to findalgorithm
header.The same behavior with the clangd binary release provided by the clangd project on Github.
Ok, so if the same issue is present with upstream clangd, then the issue primarily isn't with llvm-mingw's packaging of clangd, but with clangd itself.
The clangd in llvm-mingw has custom defaults, like defaulting to libc++ instead of libstdc++, which could make it harder to find headers in a GCC install. But if the problem exists with a default clangd as well, that's trickier.
Can you, with a vanilla clangd, try executing clangd --check=path/to/source.cpp
and quote what it outputs, for such a case? And include the relevant command parts from your compile_commands.json
so we see what it really has included there.
This is from the official clangd:
I[23:48:19.097] clangd version 18.1.3 (https://github.com/llvm/llvm-project c13b7485b87909fcf739f62cfa382b55407433c0)
I[23:48:19.097] Features: windows+grpc
I[23:48:19.097] PID: 2964
I[23:48:19.097] Working directory: G:\test1
I[23:48:19.097] argv[0]: clangd.exe
I[23:48:19.097] argv[1]: --check=test.cpp
I[23:48:19.099] Entering check mode (no LSP server)
I[23:48:19.099] Testing on source file G:\test1\test.cpp
I[23:48:19.100] Loading compilation database...
I[23:48:19.101] Loaded compilation database from G:\test1\build/compile_commands.json
I[23:48:19.101] Compile command from CDB is: [G:/test1/build] "C:\\w64devkit\\bin\\c++.exe" --driver-mode=g++ -o "CMakeFiles\\test1.dir\\test.cpp.obj" -c "-resource-dir=C:\\Work\\clangd_18.1.3\\lib\\clang\\18" -- "G:\\test1\\test.cpp"
I[23:48:19.102] Parsing command...
I[23:48:19.107] internal (cc1) args are: -cc1 -triple x86_64-pc-windows-msvc19.33.0 -fsyntax-only -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name test.cpp -mrelocation-model pic -pic-level 2 -mframe-pointer=none -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -fdebug-compilation-dir=G:/test1/build -fcoverage-compilation-dir=G:/test1/build -resource-dir "C:\\Work\\clangd_18.1.3\\lib\\clang\\18" -internal-isystem "C:\\Work\\clangd_18.1.3\\lib\\clang\\18\\include" -internal-isystem "C:/Program Files/Microsoft Visual Studio 10.0/VC/include" -internal-isystem "C:/Program Files/Microsoft Visual Studio 9.0/VC/include" -internal-isystem "C:/Program Files/Microsoft Visual Studio 9.0/VC/PlatformSDK/Include" -internal-isystem "C:/Program Files/Microsoft Visual Studio 8/VC/include" -internal-isystem "C:/Program Files/Microsoft Visual Studio 8/VC/PlatformSDK/Include" -fdeprecated-macro -ferror-limit 19 -fno-use-cxa-atexit -fms-extensions -fms-compatibility -fms-compatibility-version=19.33 -std=c++14 -fskip-odr-check-in-gmf -fdelayed-template-parsing -fcxx-exceptions -fexceptions -no-round-trip-args -faddrsig -x c++ "G:\\test1\\test.cpp"
I[23:48:19.107] Building preamble...
I[23:48:19.115] Built preamble of size 234976 for file G:\test1\test.cpp version null in 0.01 seconds
I[23:48:19.115] Indexing headers...
E[23:48:19.115] [pp_file_not_found] Line 1: 'iostream' file not found
I[23:48:19.115] Building AST...
E[23:48:19.124] IncludeCleaner: Failed to get an entry for resolved path : no such file or directory
E[23:48:19.124] IncludeCleaner: Failed to get an entry for resolved path : no such file or directory
E[23:48:19.124] [undeclared_var_use] Line 12: use of undeclared identifier 'abs'
E[23:48:19.124] [undeclared_var_use] Line 12: use of undeclared identifier 'sqrt'
E[23:48:19.124] [undeclared_var_use] Line 25: use of undeclared identifier 'cout'
E[23:48:19.124] [undeclared_var_use] Line 26: use of undeclared identifier 'cout'
I[23:48:19.124] Indexing AST...
I[23:48:19.124] Building inlay hints
I[23:48:19.124] Building semantic highlighting
I[23:48:19.124] Testing features at each token (may be slow in large files)
E[23:48:19.126] IncludeCleaner: Failed to get an entry for resolved path : no such file or directory
E[23:48:19.126] IncludeCleaner: Failed to get an entry for resolved path : no such file or directory
E[23:48:19.129] IncludeCleaner: Failed to get an entry for resolved path : no such file or directory
E[23:48:19.129] IncludeCleaner: Failed to get an entry for resolved path : no such file or directory
E[23:48:19.130] IncludeCleaner: Failed to get an entry for resolved path : no such file or directory
E[23:48:19.130] IncludeCleaner: Failed to get an entry for resolved path : no such file or directory
E[23:48:19.130] IncludeCleaner: Failed to get an entry for resolved path : no such file or directory
E[23:48:19.130] IncludeCleaner: Failed to get an entry for resolved path : no such file or directory
E[23:48:19.131] IncludeCleaner: Failed to get an entry for resolved path : no such file or directory
E[23:48:19.131] IncludeCleaner: Failed to get an entry for resolved path : no such file or directory
E[23:48:19.131] IncludeCleaner: Failed to get an entry for resolved path : no such file or directory
E[23:48:19.131] IncludeCleaner: Failed to get an entry for resolved path : no such file or directory
E[23:48:19.132] IncludeCleaner: Failed to get an entry for resolved path : no such file or directory
E[23:48:19.132] IncludeCleaner: Failed to get an entry for resolved path : no such file or directory
E[23:48:19.133] IncludeCleaner: Failed to get an entry for resolved path : no such file or directory
E[23:48:19.133] IncludeCleaner: Failed to get an entry for resolved path : no such file or directory
E[23:48:19.134] IncludeCleaner: Failed to get an entry for resolved path : no such file or directory
E[23:48:19.134] IncludeCleaner: Failed to get an entry for resolved path : no such file or directory
E[23:48:19.134] IncludeCleaner: Failed to get an entry for resolved path : no such file or directory
E[23:48:19.134] IncludeCleaner: Failed to get an entry for resolved path : no such file or directory
E[23:48:19.135] IncludeCleaner: Failed to get an entry for resolved path : no such file or directory
E[23:48:19.135] IncludeCleaner: Failed to get an entry for resolved path : no such file or directory
E[23:48:19.136] IncludeCleaner: Failed to get an entry for resolved path : no such file or directory
E[23:48:19.136] IncludeCleaner: Failed to get an entry for resolved path : no such file or directory
E[23:48:19.137] IncludeCleaner: Failed to get an entry for resolved path : no such file or directory
E[23:48:19.137] IncludeCleaner: Failed to get an entry for resolved path : no such file or directory
E[23:48:19.137] IncludeCleaner: Failed to get an entry for resolved path : no such file or directory
E[23:48:19.137] IncludeCleaner: Failed to get an entry for resolved path : no such file or directory
E[23:48:19.138] IncludeCleaner: Failed to get an entry for resolved path : no such file or directory
E[23:48:19.138] IncludeCleaner: Failed to get an entry for resolved path : no such file or directory
E[23:48:19.138] IncludeCleaner: Failed to get an entry for resolved path : no such file or directory
E[23:48:19.138] IncludeCleaner: Failed to get an entry for resolved path : no such file or directory
E[23:48:19.140] IncludeCleaner: Failed to get an entry for resolved path : no such file or directory
E[23:48:19.140] IncludeCleaner: Failed to get an entry for resolved path : no such file or directory
E[23:48:19.140] IncludeCleaner: Failed to get an entry for resolved path : no such file or directory
E[23:48:19.140] IncludeCleaner: Failed to get an entry for resolved path : no such file or directory
E[23:48:19.141] IncludeCleaner: Failed to get an entry for resolved path : no such file or directory
E[23:48:19.141] IncludeCleaner: Failed to get an entry for resolved path : no such file or directory
E[23:48:19.142] IncludeCleaner: Failed to get an entry for resolved path : no such file or directory
E[23:48:19.142] IncludeCleaner: Failed to get an entry for resolved path : no such file or directory
E[23:48:19.143] IncludeCleaner: Failed to get an entry for resolved path : no such file or directory
E[23:48:19.143] IncludeCleaner: Failed to get an entry for resolved path : no such file or directory
E[23:48:19.143] IncludeCleaner: Failed to get an entry for resolved path : no such file or directory
E[23:48:19.143] IncludeCleaner: Failed to get an entry for resolved path : no such file or directory
E[23:48:19.144] IncludeCleaner: Failed to get an entry for resolved path : no such file or directory
E[23:48:19.144] IncludeCleaner: Failed to get an entry for resolved path : no such file or directory
E[23:48:19.144] IncludeCleaner: Failed to get an entry for resolved path : no such file or directory
E[23:48:19.144] IncludeCleaner: Failed to get an entry for resolved path : no such file or directory
E[23:48:19.145] IncludeCleaner: Failed to get an entry for resolved path : no such file or directory
E[23:48:19.145] IncludeCleaner: Failed to get an entry for resolved path : no such file or directory
E[23:48:19.146] IncludeCleaner: Failed to get an entry for resolved path : no such file or directory
E[23:48:19.146] IncludeCleaner: Failed to get an entry for resolved path : no such file or directory
E[23:48:19.147] IncludeCleaner: Failed to get an entry for resolved path : no such file or directory
E[23:48:19.147] IncludeCleaner: Failed to get an entry for resolved path : no such file or directory
E[23:48:19.148] IncludeCleaner: Failed to get an entry for resolved path : no such file or directory
E[23:48:19.148] IncludeCleaner: Failed to get an entry for resolved path : no such file or directory
E[23:48:19.148] IncludeCleaner: Failed to get an entry for resolved path : no such file or directory
E[23:48:19.148] IncludeCleaner: Failed to get an entry for resolved path : no such file or directory
E[23:48:19.149] IncludeCleaner: Failed to get an entry for resolved path : no such file or directory
E[23:48:19.149] IncludeCleaner: Failed to get an entry for resolved path : no such file or directory
E[23:48:19.150] IncludeCleaner: Failed to get an entry for resolved path : no such file or directory
E[23:48:19.150] IncludeCleaner: Failed to get an entry for resolved path : no such file or directory
E[23:48:19.151] IncludeCleaner: Failed to get an entry for resolved path : no such file or directory
E[23:48:19.151] IncludeCleaner: Failed to get an entry for resolved path : no such file or directory
E[23:48:19.151] IncludeCleaner: Failed to get an entry for resolved path : no such file or directory
E[23:48:19.151] IncludeCleaner: Failed to get an entry for resolved path : no such file or directory
E[23:48:19.152] IncludeCleaner: Failed to get an entry for resolved path : no such file or directory
E[23:48:19.152] IncludeCleaner: Failed to get an entry for resolved path : no such file or directory
E[23:48:19.153] IncludeCleaner: Failed to get an entry for resolved path : no such file or directory
E[23:48:19.153] IncludeCleaner: Failed to get an entry for resolved path : no such file or directory
E[23:48:19.154] IncludeCleaner: Failed to get an entry for resolved path : no such file or directory
E[23:48:19.154] IncludeCleaner: Failed to get an entry for resolved path : no such file or directory
E[23:48:19.154] IncludeCleaner: Failed to get an entry for resolved path : no such file or directory
E[23:48:19.154] IncludeCleaner: Failed to get an entry for resolved path : no such file or directory
E[23:48:19.155] IncludeCleaner: Failed to get an entry for resolved path : no such file or directory
E[23:48:19.155] IncludeCleaner: Failed to get an entry for resolved path : no such file or directory
I[23:48:19.156] All checks completed, 5 errors
p/s: I switched to w64devkit's GCC.
compile_commands.json
generated by CMake (without the hack to manually add the path to the standard library):
[
{
"directory": "G:/test1/build",
"command": "C:\\w64devkit\\bin\\c++.exe -o CMakeFiles\\test1.dir\\test.cpp.obj -c G:\\test1\\test.cpp",
"file": "G:\\test1\\test.cpp",
"output": "CMakeFiles\\test1.dir\\test.cpp.obj"
}
]
Ok, I see... from the log above, [23:48:19.107] internal (cc1) args are: -cc1 -triple x86_64-pc-windows-msvc19.33.0 ...
. So because this clangd is built defaulting to MSVC mode, when it sees a command line like C:\\w64devkit\\bin\\c++.exe -o CMakeFiles\\test1.dir\\test.cpp.obj -c G:\\test1\\test.cpp
, it has no reason to think that this would be mingw mode. This is a kinda tricky situation, if there's not enough details to guess the actual mode being used, and the defaults don't match.
It may work better if you'd set up your cmake invocation, so that it invokes x86_64-w64-mingw32-g++
instead of just c++.exe
, if that's available in w64devkit - that may make it clearer what the tool tries to do.
Another alternative, could be if llvm-mingw would provide a clangd, which defaults to mingw mode (like it does) but without assuming the other llvm-mingw specific defaults.
Can you try the same clangd --check
command with the llvm-mingw based clang, and see what it prints similarly?
I tried doing a tweaked build of llvm-mingw, where the libc++ choice and similar isn't hardcoded, but set via config files, which may work better for cases like this. At https://github.com/mstorsjo/llvm-mingw/actions/runs/10958117646 you can find binaries from that (the binaries will be available for 7 days only). So ideally I'd like to see the clangd --check
output both with the usual llvm-mingw release clangd, and with clangd from the binaries from that test build above.
I have the impression that clangd will always stick with the toolchain it was built for. I have used winlibs.com's mingw distro in the past. It includes Clang even though this Clang is configured to use GNU binutils and libstdc++. The performance of the clangd included in winlibs.com's distro is worse than llvm-mingw, but it also has the same problem as the clangd of llvm-mingw, that is it will only work with winlibs.com's compiler. I was unable to use it with other mingw distros, as I recall. This is the story of about two years ago. Now I don't use Windows as the development platform anymore and only build and test software on it occasionally.
One exception might be the clangd of MSYS2 (clang-tools-extra). As I recall, it's able to work with other mingw compilers. By work, I mean getting code completion. It's too long ago and I could remember it wrong, though.
Usual llvm-mingw:
I[13:55:38.662] clangd version 19.1.0 (https://github.com/llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)
I[13:55:38.662] Features: windows
I[13:55:38.662] PID: 3964
I[13:55:38.662] Working directory: G:/test1
I[13:55:38.662] argv[0]: clangd.exe
I[13:55:38.662] argv[1]: --check=test.cpp
I[13:55:38.663] Entering check mode (no LSP server)
I[13:55:38.663] Testing on source file G:/test1/test.cpp
I[13:55:38.663] Loading compilation database...
I[13:55:38.664] Loaded compilation database from G:/test1/build/compile_commands.json
I[13:55:38.664] Compile command from CDB is: [G:/test1/build] C:/w64devkit/bin/c++.exe --driver-mode=g++ -o "CMakeFiles\\test1.dir\\test.cpp.obj" -c -resource-dir=C:/Work/llvm-mingw-20240917-ucrt-x86_64/lib/clang/19 -- G:/test1/test.cpp
I[13:55:38.664] Parsing command...
I[13:55:38.665] internal (cc1) args are: -cc1 -triple x86_64-w64-windows-gnu -fsyntax-only -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name test.cpp -mrelocation-model pic -pic-level 2 -mframe-pointer=none -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -mms-bitfields -funwind-tables=2 -fno-sized-deallocation -fno-use-init-array -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=G:/test1/build -fcoverage-compilation-dir=G:/test1/build -resource-dir C:/Work/llvm-mingw-20240917-ucrt-x86_64/lib/clang/19 -internal-isystem C:/w64devkit/x86_64-w64-mingw32/include/c++/v1 -internal-isystem C:/w64devkit/include/c++/v1 -internal-isystem C:/Work/llvm-mingw-20240917-ucrt-x86_64/lib/clang/19/include -internal-isystem C:/w64devkit/x86_64-w64-mingw32/include -internal-isystem C:/w64devkit/x86_64-w64-mingw32/usr/include -internal-isystem C:/w64devkit/include -fdeprecated-macro -ferror-limit 19 -fno-use-cxa-atexit -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -fcxx-exceptions -fexceptions -exception-model=seh -no-round-trip-args -faddrsig -x c++ G:/test1/test.cpp
I[13:55:38.666] Building preamble...
I[13:55:38.675] Built preamble of size 256984 for file G:/test1/test.cpp version null in 0.01 seconds
I[13:55:38.675] Indexing headers...
E[13:55:38.675] [pp_file_not_found] Line 1: 'iostream' file not found
I[13:55:38.675] Building AST...
E[13:55:38.681] IncludeCleaner: Failed to get an entry for resolved path : No such file or directory
E[13:55:38.681] IncludeCleaner: Failed to get an entry for resolved path : No such file or directory
E[13:55:38.682] [undeclared_var_use] Line 12: use of undeclared identifier 'abs'
E[13:55:38.682] [undeclared_var_use] Line 12: use of undeclared identifier 'sqrt'
E[13:55:38.682] [undeclared_var_use] Line 25: use of undeclared identifier 'cout'
E[13:55:38.682] [undeclared_var_use] Line 26: use of undeclared identifier 'cout'
I[13:55:38.682] Indexing AST...
I[13:55:38.682] Building inlay hints
I[13:55:38.682] Building semantic highlighting
I[13:55:38.682] Testing features at each token (may be slow in large files)
E[13:55:38.683] IncludeCleaner: Failed to get an entry for resolved path : No such file or directory
E[13:55:38.683] IncludeCleaner: Failed to get an entry for resolved path : No such file or directory
E[13:55:38.686] IncludeCleaner: Failed to get an entry for resolved path : No such file or directory
E[13:55:38.686] IncludeCleaner: Failed to get an entry for resolved path : No such file or directory
E[13:55:38.687] IncludeCleaner: Failed to get an entry for resolved path : No such file or directory
E[13:55:38.687] IncludeCleaner: Failed to get an entry for resolved path : No such file or directory
E[13:55:38.687] IncludeCleaner: Failed to get an entry for resolved path : No such file or directory
E[13:55:38.687] IncludeCleaner: Failed to get an entry for resolved path : No such file or directory
E[13:55:38.688] IncludeCleaner: Failed to get an entry for resolved path : No such file or directory
E[13:55:38.688] IncludeCleaner: Failed to get an entry for resolved path : No such file or directory
E[13:55:38.688] IncludeCleaner: Failed to get an entry for resolved path : No such file or directory
E[13:55:38.688] IncludeCleaner: Failed to get an entry for resolved path : No such file or directory
E[13:55:38.689] IncludeCleaner: Failed to get an entry for resolved path : No such file or directory
E[13:55:38.689] IncludeCleaner: Failed to get an entry for resolved path : No such file or directory
E[13:55:38.690] IncludeCleaner: Failed to get an entry for resolved path : No such file or directory
E[13:55:38.690] IncludeCleaner: Failed to get an entry for resolved path : No such file or directory
E[13:55:38.691] IncludeCleaner: Failed to get an entry for resolved path : No such file or directory
E[13:55:38.691] IncludeCleaner: Failed to get an entry for resolved path : No such file or directory
E[13:55:38.691] IncludeCleaner: Failed to get an entry for resolved path : No such file or directory
E[13:55:38.691] IncludeCleaner: Failed to get an entry for resolved path : No such file or directory
E[13:55:38.692] IncludeCleaner: Failed to get an entry for resolved path : No such file or directory
E[13:55:38.692] IncludeCleaner: Failed to get an entry for resolved path : No such file or directory
E[13:55:38.693] IncludeCleaner: Failed to get an entry for resolved path : No such file or directory
E[13:55:38.693] IncludeCleaner: Failed to get an entry for resolved path : No such file or directory
E[13:55:38.694] IncludeCleaner: Failed to get an entry for resolved path : No such file or directory
E[13:55:38.694] IncludeCleaner: Failed to get an entry for resolved path : No such file or directory
E[13:55:38.694] IncludeCleaner: Failed to get an entry for resolved path : No such file or directory
E[13:55:38.694] IncludeCleaner: Failed to get an entry for resolved path : No such file or directory
E[13:55:38.695] IncludeCleaner: Failed to get an entry for resolved path : No such file or directory
E[13:55:38.695] IncludeCleaner: Failed to get an entry for resolved path : No such file or directory
E[13:55:38.695] IncludeCleaner: Failed to get an entry for resolved path : No such file or directory
E[13:55:38.695] IncludeCleaner: Failed to get an entry for resolved path : No such file or directory
E[13:55:38.696] IncludeCleaner: Failed to get an entry for resolved path : No such file or directory
E[13:55:38.696] IncludeCleaner: Failed to get an entry for resolved path : No such file or directory
E[13:55:38.697] IncludeCleaner: Failed to get an entry for resolved path : No such file or directory
E[13:55:38.697] IncludeCleaner: Failed to get an entry for resolved path : No such file or directory
E[13:55:38.698] IncludeCleaner: Failed to get an entry for resolved path : No such file or directory
E[13:55:38.698] IncludeCleaner: Failed to get an entry for resolved path : No such file or directory
E[13:55:38.699] IncludeCleaner: Failed to get an entry for resolved path : No such file or directory
E[13:55:38.699] IncludeCleaner: Failed to get an entry for resolved path : No such file or directory
E[13:55:38.700] IncludeCleaner: Failed to get an entry for resolved path : No such file or directory
E[13:55:38.700] IncludeCleaner: Failed to get an entry for resolved path : No such file or directory
E[13:55:38.700] IncludeCleaner: Failed to get an entry for resolved path : No such file or directory
E[13:55:38.700] IncludeCleaner: Failed to get an entry for resolved path : No such file or directory
E[13:55:38.701] IncludeCleaner: Failed to get an entry for resolved path : No such file or directory
E[13:55:38.701] IncludeCleaner: Failed to get an entry for resolved path : No such file or directory
E[13:55:38.701] IncludeCleaner: Failed to get an entry for resolved path : No such file or directory
E[13:55:38.701] IncludeCleaner: Failed to get an entry for resolved path : No such file or directory
E[13:55:38.702] IncludeCleaner: Failed to get an entry for resolved path : No such file or directory
E[13:55:38.702] IncludeCleaner: Failed to get an entry for resolved path : No such file or directory
E[13:55:38.703] IncludeCleaner: Failed to get an entry for resolved path : No such file or directory
E[13:55:38.703] IncludeCleaner: Failed to get an entry for resolved path : No such file or directory
E[13:55:38.704] IncludeCleaner: Failed to get an entry for resolved path : No such file or directory
E[13:55:38.704] IncludeCleaner: Failed to get an entry for resolved path : No such file or directory
E[13:55:38.704] IncludeCleaner: Failed to get an entry for resolved path : No such file or directory
E[13:55:38.704] IncludeCleaner: Failed to get an entry for resolved path : No such file or directory
E[13:55:38.705] IncludeCleaner: Failed to get an entry for resolved path : No such file or directory
E[13:55:38.705] IncludeCleaner: Failed to get an entry for resolved path : No such file or directory
E[13:55:38.706] IncludeCleaner: Failed to get an entry for resolved path : No such file or directory
E[13:55:38.706] IncludeCleaner: Failed to get an entry for resolved path : No such file or directory
E[13:55:38.707] IncludeCleaner: Failed to get an entry for resolved path : No such file or directory
E[13:55:38.707] IncludeCleaner: Failed to get an entry for resolved path : No such file or directory
E[13:55:38.707] IncludeCleaner: Failed to get an entry for resolved path : No such file or directory
E[13:55:38.707] IncludeCleaner: Failed to get an entry for resolved path : No such file or directory
E[13:55:38.708] IncludeCleaner: Failed to get an entry for resolved path : No such file or directory
E[13:55:38.708] IncludeCleaner: Failed to get an entry for resolved path : No such file or directory
E[13:55:38.709] IncludeCleaner: Failed to get an entry for resolved path : No such file or directory
E[13:55:38.709] IncludeCleaner: Failed to get an entry for resolved path : No such file or directory
E[13:55:38.710] IncludeCleaner: Failed to get an entry for resolved path : No such file or directory
E[13:55:38.710] IncludeCleaner: Failed to get an entry for resolved path : No such file or directory
E[13:55:38.710] IncludeCleaner: Failed to get an entry for resolved path : No such file or directory
E[13:55:38.710] IncludeCleaner: Failed to get an entry for resolved path : No such file or directory
E[13:55:38.711] IncludeCleaner: Failed to get an entry for resolved path : No such file or directory
E[13:55:38.711] IncludeCleaner: Failed to get an entry for resolved path : No such file or directory
E[13:55:38.711] IncludeCleaner: Failed to get an entry for resolved path : No such file or directory
E[13:55:38.711] IncludeCleaner: Failed to get an entry for resolved path : No such file or directory
I[13:55:38.713] All checks completed, 5 errors
windows-ucrt-x86_64-toolchain artifact:
I[14:02:40.400] clangd version 19.1.0 (https://github.com/llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)
I[14:02:40.400] Features: windows
I[14:02:40.400] PID: 3340
I[14:02:40.400] Working directory: G:/test1
I[14:02:40.400] argv[0]: clangd.exe
I[14:02:40.400] argv[1]: --check=test.cpp
I[14:02:40.401] Entering check mode (no LSP server)
I[14:02:40.401] Testing on source file G:/test1/test.cpp
I[14:02:40.401] Loading compilation database...
I[14:02:40.402] Loaded compilation database from G:/test1/build/compile_commands.json
I[14:02:40.403] Compile command from CDB is: [G:/test1/build] C:/w64devkit/bin/c++.exe --driver-mode=g++ -o "CMakeFiles\\test1.dir\\test.cpp.obj" -c -resource-dir=C:/Work/llvm-mingw-20240920-ucrt-x86_64/lib/clang/19 -- G:/test1/test.cpp
I[14:02:40.403] Parsing command...
I[14:02:40.404] internal (cc1) args are: -cc1 -triple x86_64-w64-windows-gnu -fsyntax-only -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name test.cpp -mrelocation-model pic -pic-level 2 -mframe-pointer=none -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -mms-bitfields -funwind-tables=2 -fno-sized-deallocation -fno-use-init-array -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=G:/test1/build -fcoverage-compilation-dir=G:/test1/build -resource-dir C:/Work/llvm-mingw-20240920-ucrt-x86_64/lib/clang/19 -internal-isystem C:/w64devkit/x86_64-w64-mingw32/include/c++ -internal-isystem C:/w64devkit/x86_64-w64-mingw32/include/c++/x86_64-w64-mingw32 -internal-isystem C:/w64devkit/x86_64-w64-mingw32/include/c++/backward -internal-isystem C:/w64devkit/x86_64-w64-mingw32/include/c++/14.2.0 -internal-isystem C:/w64devkit/x86_64-w64-mingw32/include/c++/14.2.0/x86_64-w64-mingw32 -internal-isystem C:/w64devkit/x86_64-w64-mingw32/include/c++/14.2.0/backward -internal-isystem C:/w64devkit/include/c++/14.2.0 -internal-isystem C:/w64devkit/include/c++/14.2.0/x86_64-w64-mingw32 -internal-isystem C:/w64devkit/include/c++/14.2.0/backward -internal-isystem C:/w64devkit/lib/gcc/x86_64-w64-mingw32/14.2.0/include/c++ -internal-isystem C:/w64devkit/lib/gcc/x86_64-w64-mingw32/14.2.0/include/c++/x86_64-w64-mingw32 -internal-isystem C:/w64devkit/lib/gcc/x86_64-w64-mingw32/14.2.0/include/c++/backward -internal-isystem C:/w64devkit/lib/gcc/x86_64-w64-mingw32/14.2.0/include/g++-v14.2.0 -internal-isystem C:/w64devkit/lib/gcc/x86_64-w64-mingw32/14.2.0/include/g++-v14.2.0/x86_64-w64-mingw32 -internal-isystem C:/w64devkit/lib/gcc/x86_64-w64-mingw32/14.2.0/include/g++-v14.2.0/backward -internal-isystem C:/w64devkit/lib/gcc/x86_64-w64-mingw32/14.2.0/include/g++-v14.2 -internal-isystem C:/w64devkit/lib/gcc/x86_64-w64-mingw32/14.2.0/include/g++-v14.2/x86_64-w64-mingw32 -internal-isystem C:/w64devkit/lib/gcc/x86_64-w64-mingw32/14.2.0/include/g++-v14.2/backward -internal-isystem C:/w64devkit/lib/gcc/x86_64-w64-mingw32/14.2.0/include/g++-v14 -internal-isystem C:/w64devkit/lib/gcc/x86_64-w64-mingw32/14.2.0/include/g++-v14/x86_64-w64-mingw32 -internal-isystem C:/w64devkit/lib/gcc/x86_64-w64-mingw32/14.2.0/include/g++-v14/backward -internal-isystem C:/Work/llvm-mingw-20240920-ucrt-x86_64/lib/clang/19/include -internal-isystem C:/w64devkit/x86_64-w64-mingw32/include -internal-isystem C:/w64devkit/x86_64-w64-mingw32/usr/include -internal-isystem C:/w64devkit/include -fdeprecated-macro -ferror-limit 19 -fno-use-cxa-atexit -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -fcxx-exceptions -fexceptions -exception-model=seh -no-round-trip-args -faddrsig -x c++ G:/test1/test.cpp
I[14:02:40.405] Building preamble...
I[14:02:40.780] Built preamble of size 4456832 for file G:/test1/test.cpp version null in 0.38 seconds
I[14:02:40.780] Indexing headers...
I[14:02:40.899] Building AST...
I[14:02:40.911] Indexing AST...
I[14:02:40.912] Building inlay hints
I[14:02:40.912] Building semantic highlighting
I[14:02:40.912] Testing features at each token (may be slow in large files)
I[14:02:40.950] All checks completed, 0 errors
So, am I reading that right, that the artifact from the test branch, which doesn't hardcode -stdlib=libc++
, seems to work for your case? As the last dump ends in All checks completed, 0 errors
? And that one has got the following,
internal (cc1) args are: -cc1 -triple x86_64-w64-windows-gnu -fsyntax-only -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name test.cpp -mrelocation-model pic -pic-level 2 -mframe-pointer=none -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -mms-bitfields -funwind-tables=2 -fno-sized-deallocation -fno-use-init-array -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=G:/test1/build -fcoverage-compilation-dir=G:/test1/build -resource-dir C:/Work/llvm-mingw-20240920-ucrt-x86_64/lib/clang/19 -internal-isystem C:/w64devkit/x86_64-w64-mingw32/include/c++ -internal-isystem C:/w64devkit/x86_64-w64-mingw32/include/c++/x86_64-w64-mingw32 -internal-isystem C:/w64devkit/x86_64-w64-mingw32/include/c++/backward -internal-isystem C:/w64devkit/x86_64-w64-mingw32/include/c++/14.2.0 -internal-isystem C:/w64devkit/x86_64-w64-mingw32/include/c++/14.2.0/x86_64-w64-mingw32 -internal-isystem C:/w64devkit/x86_64-w64-mingw32/include/c++/14.2.0/backward -internal-isystem C:/w64devkit/include/c++/14.2.0 -internal-isystem C:/w64devkit/include/c++/14.2.0/x86_64-w64-mingw32 -internal-isystem C:/w64devkit/include/c++/14.2.0/backward -internal-isystem C:/w64devkit/lib/gcc/x86_64-w64-mingw32/14.2.0/include/c++ -internal-isystem C:/w64devkit/lib/gcc/x86_64-w64-mingw32/14.2.0/include/c++/x86_64-w64-mingw32 -internal-isystem C:/w64devkit/lib/gcc/x86_64-w64-mingw32/14.2.0/include/c++/backward -internal-isystem C:/w64devkit/lib/gcc/x86_64-w64-mingw32/14.2.0/include/g++-v14.2.0 -internal-isystem C:/w64devkit/lib/gcc/x86_64-w64-mingw32/14.2.0/include/g++-v14.2.0/x86_64-w64-mingw32 -internal-isystem C:/w64devkit/lib/gcc/x86_64-w64-mingw32/14.2.0/include/g++-v14.2.0/backward -internal-isystem C:/w64devkit/lib/gcc/x86_64-w64-mingw32/14.2.0/include/g++-v14.2 -internal-isystem C:/w64devkit/lib/gcc/x86_64-w64-mingw32/14.2.0/include/g++-v14.2/x86_64-w64-mingw32 -internal-isystem C:/w64devkit/lib/gcc/x86_64-w64-mingw32/14.2.0/include/g++-v14.2/backward -internal-isystem C:/w64devkit/lib/gcc/x86_64-w64-mingw32/14.2.0/include/g++-v14 -internal-isystem C:/w64devkit/lib/gcc/x86_64-w64-mingw32/14.2.0/include/g++-v14/x86_64-w64-mingw32 -internal-isystem C:/w64devkit/lib/gcc/x86_64-w64-mingw32/14.2.0/include/g++-v14/backward -internal-isystem C:/Work/llvm-mingw-20240920-ucrt-x86_64/lib/clang/19/include -internal-isystem C:/w64devkit/x86_64-w64-mingw32/include -internal-isystem C:/w64devkit/x86_64-w64-mingw32/usr/include -internal-isystem C:/w64devkit/include -fdeprecated-macro -ferror-limit 19 -fno-use-cxa-atexit -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -fcxx-exceptions -fexceptions -exception-model=seh -no-round-trip-args -faddrsig -x c++ G:/test1/test.cpp
, which seems right.
The clangd of windows-ucrt-x86_64-toolchain artifact works.
It seems you don't need to change any defaults. There is --query-driver
: https://github.com/clangd/clangd/issues/2155#issuecomment-2370116342
It seems you don't need to change any defaults. There is
--query-driver
: clangd/clangd#2155 (comment)
Oh, that looks like a neat fix for the problem!
--query-driver
doesn't work for me.
--query-driver
doesn't work for me.
Did you try this with both the msvc clangd or the llvm-mingw one? Can you test both? And please test it with the --check
option and share the output so we can see what it tries to do, if it did have any effect.
--query-driver
doesn't work for me.Did you try this with both the msvc clangd or the llvm-mingw one? Can you test both? And please test it with the
--check
option and share the output so we can see what it tries to do, if it did have any effect.
~I only test with llvm-mingw's clangd. The --check
option has the same result with or without --query-driver
.~
Update: --query-driver
worked for both llvm-mingw's clangd and official clangd. But I need to use forward slashes for path.
This worked:
clangd --check=test.cpp --query-driver=C:/w64devkit/bin/c++.exe
This doesn't:
clangd --check=test.cpp --query-driver=C:\\w64devkit\\bin\\c++.exe
--query-driver
is a bit tricky to get working. It's explained at https://clangd.llvm.org/guides/system-headers#query-driver but based on user reports it frequently trips users up.
--query-driver=/path/to/compiler
is not an instruction to clangd to query /path/to/compiler
for built-in includes; it's a permission that it's allowed to query /path/to/compiler
, if /path/to/compiler
appears as the compiler in a given compile command.
So, to get it to work you need:
compile_commands.json
file, or alternatively to specify a compiler path using https://clangd.llvm.org/config.html#compiler.compile_commands.json
(or the compiler path specified in the config file) needs to be the full path of the compiler you want to query.--query-driver
needs to be specified with a matching path as a value.
--query-driver
is a bit tricky to get working. It's explained at https://clangd.llvm.org/guides/system-headers#query-driver but based on user reports it frequently trips users up.
--query-driver=/path/to/compiler
is not an instruction to clangd to query/path/to/compiler
for built-in includes; it's a permission that it's allowed to query/path/to/compiler
, if/path/to/compiler
appears as the compiler in a given compile command.So, to get it to work you need:
1. To have a `compile_commands.json` file, or alternative to specify a compiler path using https://clangd.llvm.org/config.html#compiler. 2. The argv[0] in the commands in `compile_commands.json` (or the compiler path specified in the config file) needs to be the full path of the compiler you want to query. 3. `--query-driver` needs to be specified with a matching path as a value.
Please see my updated comment above.
You can see my compile_commands.json
on https://github.com/mstorsjo/llvm-mingw/issues/454#issuecomment-2361642171. It uses backward slashes: C:\\w64devkit\\bin\\c++.exe
. But backward slashes path will not work with --query-driver
. You have to use forward slashes path: C:/w64devkit/bin/c++.exe
.
Update:
--query-driver
worked for both llvm-mingw's clangd and official clangd. But I need to use forward slashes for path.This worked:
clangd --check=test.cpp --query-driver=C:/w64devkit/bin/c++.exe
This doesn't:
clangd --check=test.cpp --query-driver=C:\\w64devkit\\bin\\c++.exe
Interesting, thanks for sharing!
I guess the double backslashes in the json are for escaping purposes - does this happen to work with backslashes if you'd use only single backslashes?
Interesting, thanks for sharing!
I guess the double backslashes in the json are for escaping purposes - does this happen to work with backslashes if you'd use only single backslashes?
Yes. I tested and found that it also works with single backslashes path.
Interesting, thanks for sharing! I guess the double backslashes in the json are for escaping purposes - does this happen to work with backslashes if you'd use only single backslashes?
Yes. I tested and found that it also works with single backslashes path.
Ok, that's good news, that probably clarifies the issue. Thanks for rechecking it!
With these workarounds, I believe this case can be closed? If I later transition llvm-mingw to use config files, as in the linked artifacts, the issue will also end up working without the --query-driver
option.
I'm on Windows. I originally use llvm-mingw as the default compiler, but some projects only support GCC. I finally decided to use niXman's GCC and llvm-mingw in parallel, which niXman's GCC has higher precedent in
PATH
so it will be picked up before llvm-mingw. I still use the clangd from llvm-mingw, though. The problem is even if I have acompiler_commands.json
generated by CMake, clangd still struggled to find standard library headers (of GCC). I examined thecompiler_commands.json
generated by CMake and I found it doesn't include the path to the standard library headers (why should it?). I hacked it to include the path to the standard library headers (of GCC) like the guy on #444, but it doesn't help. It will always struggled to findalgorithm
header.The same behavior with the clangd binary release provided by the clangd project on Github.