I've been using Neovim with clangd for C, and I'm encountering an issue with my configuration when working with C++ files that include windows.h
. While I've set up my configuration file config.yaml
to use MinGW compilers without any problem for C files, it seems like clangd can't find windows.h
when processing C++ files.
These is my old config.yaml
(was working well with c):
CompileFlags:
Compiler: x86_64-w64-mingw32-gcc
Add: ["-I../headers", "-I$INCLUDE_PATH"]
But now i want to work with c++, so
Here's my new config.yaml
:
If:
PathMatch: .*\.c .*\.h
CompileFlags:
Compiler: x86_64-w64-mingw32-gcc
Add: ["-I../headers", "-I$INCLUDE_PATH"]
---
If:
PathMatch: .*\.cpp .*\.hpp
CompileFlags:
Compiler: x86_64-w64-mingw32-g++
Add: ["-I../headers", "-I$INCLUDE_PATH"]
---
And these happens:
[Edit]: I didn't noticed that i didn't use std namespace.
Even though the it compiles without any issues.
These is neovim LSP log if it's can help.
[START][2024-05-01 19:22:24] LSP logging initiated
[ERROR][2024-05-01 19:22:24] .../vim/lsp/rpc.lua:734 "rpc" "/home/panda/.local/share/nvim/mason/bin/clangd" "stderr" "I[19:22:24.429] clangd version 17.0.3 (https://github.com/llvm/llvm-project 888437e1b60011b8a375dd30928ec925b448da57)\nI[19:22:24.429] Features: linux+grpc\nI[19:22:24.429] PID: 1238686\nI[19:22:24.429] Working directory: /home/panda/path/to\nI[19:22:24.429] argv[0]: /home/panda/.local/share/nvim/mason/bin/clangd\nI[19:22:24.429] Starting LSP over stdin/stdout\nI[19:22:24.429] <-- initialize(1)\n"
[ERROR][2024-05-01 19:22:24] .../vim/lsp/rpc.lua:734 "rpc" "/home/panda/.local/share/nvim/mason/bin/clangd" "stderr" "I[19:22:24.430] --> reply:initialize(1) 0 ms\n"
[ERROR][2024-05-01 19:22:24] .../vim/lsp/rpc.lua:734 "rpc" "/home/panda/.local/share/nvim/mason/bin/clangd" "stderr" "I[19:22:24.431] <-- initialized\nI[19:22:24.432] <-- textDocument/didOpen\nE[19:22:24.432] config error at /home/panda/.config/clangd/config.yaml:24:0: Config should be a dictionary\nI[19:22:24.432] --> textDocument/publishDiagnostics\nI[19:22:24.432] Failed to find compilation database for /home/panda/path/to/main.cpp\nI[19:22:24.432] ASTWorker building file /home/panda/path/to/main.cpp version 0 with command clangd fallback\n[/home/panda/path/to]\n/usr/lib/llvm-16/bin/clang -resource-dir=/home/panda/.local/share/nvim/mason/packages/clangd/clangd_17.0.3/lib/clang/17 -- /home/panda/path/to/main.cpp\n"
[ERROR][2024-05-01 19:22:24] .../vim/lsp/rpc.lua:734 "rpc" "/home/panda/.local/share/nvim/mason/bin/clangd" "stderr" "I[19:22:24.678] Built preamble of size 3580972 for file /home/panda/path/to/main.cpp version 0 in 0.25 seconds\n"
[ERROR][2024-05-01 19:22:24] .../vim/lsp/rpc.lua:734 "rpc" "/home/panda/.local/share/nvim/mason/bin/clangd" "stderr" "I[19:22:24.678] --> workspace/semanticTokens/refresh(0)\n"
[ERROR][2024-05-01 19:22:24] .../vim/lsp/rpc.lua:734 "rpc" "/home/panda/.local/share/nvim/mason/bin/clangd" "stderr" "I[19:22:24.679] Indexing c++17 standard library in the context of /home/panda/path/to/main.cpp\n"
[ERROR][2024-05-01 19:22:24] .../vim/lsp/rpc.lua:734 "rpc" "/home/panda/.local/share/nvim/mason/bin/clangd" "stderr" "I[19:22:24.679] <-- reply(0)\n"
[ERROR][2024-05-01 19:22:24] .../vim/lsp/rpc.lua:734 "rpc" "/home/panda/.local/share/nvim/mason/bin/clangd" "stderr" "E[19:22:24.685] IncludeCleaner: Failed to get an entry for resolved path : No such file or directory\n"
[ERROR][2024-05-01 19:22:24] .../vim/lsp/rpc.lua:734 "rpc" "/home/panda/.local/share/nvim/mason/bin/clangd" "stderr" "I[19:22:24.685] --> textDocument/publishDiagnostics\n"
[ERROR][2024-05-01 19:22:24] .../vim/lsp/rpc.lua:734 "rpc" "/home/panda/.local/share/nvim/mason/bin/clangd" "stderr" "I[19:22:24.689] <-- textDocument/signatureHelp(2)\n"
[ERROR][2024-05-01 19:22:24] .../vim/lsp/rpc.lua:734 "rpc" "/home/panda/.local/share/nvim/mason/bin/clangd" "stderr" "I[19:22:24.691] --> reply:textDocument/signatureHelp(2) 2 ms\n"
[ERROR][2024-05-01 19:22:25] .../vim/lsp/rpc.lua:734 "rpc" "/home/panda/.local/share/nvim/mason/bin/clangd" "stderr" "I[19:22:25.962] Indexed c++17 standard library (incomplete due to errors): 13604 symbols, 1918 filtered\n"
[ERROR][2024-05-01 19:22:26] .../vim/lsp/rpc.lua:734 "rpc" "/home/panda/.local/share/nvim/mason/bin/clangd" "stderr" "I[19:22:26.750] <-- textDocument/didSave\n"
[ERROR][2024-05-01 19:22:26] .../vim/lsp/rpc.lua:734 "rpc" "/home/panda/.local/share/nvim/mason/bin/clangd" "stderr" "I[19:22:26.750] File version went from 0 to 0\n"
[ERROR][2024-05-01 19:22:26] .../vim/lsp/rpc.lua:734 "rpc" "/home/panda/.local/share/nvim/mason/bin/clangd" "stderr" "I[19:22:26.800] Failed to find compilation database for /home/panda/path/to/main.cpp\n"
[ERROR][2024-05-01 19:22:26] .../vim/lsp/rpc.lua:734 "rpc" "/home/panda/.local/share/nvim/mason/bin/clangd" "stderr" "I[19:22:26.800] ASTWorker building file /home/panda/path/to/main.cpp version 0 with command clangd fallback\n[/home/panda/path/to]\n/usr/lib/llvm-16/bin/clang -resource-dir=/home/panda/.local/share/nvim/mason/packages/clangd/clangd_17.0.3/lib/clang/17 -- /home/panda/path/to/main.cpp\n"
[ERROR][2024-05-01 19:22:27] .../vim/lsp/rpc.lua:734 "rpc" "/home/panda/.local/share/nvim/mason/bin/clangd" "stderr" "I[19:22:27.008] <-- textDocument/signatureHelp(3)\n"
[ERROR][2024-05-01 19:22:27] .../vim/lsp/rpc.lua:734 "rpc" "/home/panda/.local/share/nvim/mason/bin/clangd" "stderr" "I[19:22:27.016] --> reply:textDocument/signatureHelp(3) 7 ms\n"
[ERROR][2024-05-01 19:22:34] .../vim/lsp/rpc.lua:734 "rpc" "/home/panda/.local/share/nvim/mason/bin/clangd" "stderr" "I[19:22:34.880] <-- textDocument/signatureHelp(4)\n"
[ERROR][2024-05-01 19:22:34] .../vim/lsp/rpc.lua:734 "rpc" "/home/panda/.local/share/nvim/mason/bin/clangd" "stderr" "I[19:22:34.888] --> reply:textDocument/signatureHelp(4) 7 ms\n"
[ERROR][2024-05-01 19:22:35] .../vim/lsp/rpc.lua:734 "rpc" "/home/panda/.local/share/nvim/mason/bin/clangd" "stderr" "I[19:22:35.437] <-- shutdown(5)\nI[19:22:35.437] --> reply:shutdown(5) 0 ms\n"
Is this problem related to my new config? If so, how can I configure clangd to use Mingw compilers for both C and C++?
I've tried adjusting the paths and configurations, but haven't had any luck so far. Any suggestions on how to resolve this?
After a couple of tries, I found out that the issue is with clangd not identifying the include directories of x86_64-w64-mingw32-g++
.
I don't exactly understand why it's working for x86_64-w64-mingw32-gcc
and not for x86_64-w64-mingw32-g++
.
However, to get around this, I located all the include directories of g++ using this command:
x86_64-w64-mingw32-g++ -print-search-dirs
and this was the output:
install: /usr/lib/gcc/x86_64-w64-mingw32/12-win32/
programs: =/usr/lib/gcc/x86_64-w64-mingw32/12-win32/:/usr/lib/gcc/x86_64-w64-mingw32/12-win32/:/usr/lib/gcc/x86_64-w64-mingw32/:/usr/lib/gcc/x86_64-w64-mingw32/12-win32/:/usr/lib/gcc/x86_64-w64-mingw32/:/usr/lib/gcc/x86_64-w64-mingw32/12-win32/../../../../x86_64-w64-mingw32/bin/x86_64-w64-mingw32/12-win32/:/usr/lib/gcc/x86_64-w64-mingw32/12-win32/../../../../x86_64-w64-mingw32/bin/
libraries: =/usr/lib/gcc/x86_64-w64-mingw32/12-win32/:/usr/lib/gcc/x86_64-w64-mingw32/12-win32/../../../../x86_64-w64-mingw32/lib/x86_64-w64-mingw32/12-win32/:/usr/lib/gcc/x86_64-w64-mingw32/12-win32/../../../../x86_64-w64-mingw32/lib/
I started missing around this path /usr/lib/gcc/x86_64-w64-mingw32/12-win32/
and made some research and these is what i got:
/usr/lib/gcc/x86_64-w64-mingw32/12-win32/include/c++
: This directory contains the main headers for the C++ standard library. It includes headers for containers (like vector, map, etc.), algorithms, iterators, and other standard C++ components.
/usr/lib/gcc/x86_64-w64-mingw32/12-win32/include/c++/x86_64-w64-mingw32
: This subdirectory contains architecture-specific headers for the C++ standard library. It may include headers that are optimized or specific to the x86_64 architecture used by MinGW-w64.
/usr/lib/gcc/x86_64-w64-mingw32/12-win32/include/c++/backward
: This subdirectory contains compatibility headers for older versions of the C++ standard library. It may include headers that maintain compatibility with older codebases or provide deprecated features.
So I did change the .config/clangd/config.yaml
to this:
If:
PathMatch: .*\.c
CompileFlags:
Compiler: x86_64-w64-mingw32-gcc
Add: ["-I../headers", "-I$INCLUDE_PATH"] # These two arguments are not affecting anything; they just match my needs.
---
If:
PathMatch: .*\.cpp
CompileFlags:
Compiler: x86_64-w64-mingw32-g++
Add: ["-I../headers", "-I$INCLUDE_PATH", "-I/usr/lib/gcc/x86_64-w64-mingw32/12-win32/include/c++", "-I/usr/lib/gcc/x86_64-w64-mingw32/12-win32/include/c++/x86_64-w64-mingw32", "-I/usr/lib/gcc/x86_64-w64-mingw32/12-win32/include/c++/backward"]
---
If you have better recommendations, Or you see i got something wrong, Please don't hesitate.