Reputation: 161
I just starting working on a Win32 application and I'm editing in Neovim. I'm running off WSL and using clangd as my LSP. To compile I'm using Microsoft cl and it's building the binary fine.
I was refactoring some code and I encountered a weird LSP error when moving my #include <dsound.h>
from it's original main.cpp to a new header file (windows_sound.h). My LSP gave me the following complaint: clang: In included file: unknown type name 'interface'.
This error shows up even when it's the only thing in the file (without include guards). However, if I move the include into an empty .cpp (windows_sound.cpp) the LSP gives me no errors. Any idea what's going on?
My .clangd (which points to MingW64's windows header files):
CompileFlags:
Add:
- "--target=x86_64-w64-windows-gnu"
- "-std=c++20"
- "-fms-extensions"
- "Wall"
- "-isystem/usr/share/mingw-w64/include/"
My clangd version: 15.0.6
nvim version: 0.8.0-1210
The only additional thing I do in my config is I modified the clangd command to:
cmd =
{
"clangd",
"--header-insertion=never",
},
Upvotes: 0
Views: 1788
Reputation: 52739
The error occuring in an .h
but not in a .cpp
file may indicate that clangd is treating the .h
file as a C header rather than a C++ header.
One solution is to rename the header to .hpp
which identifies it as a C++ header.
Another solution is to instruct clangd to parse .h
files in your project as C++ headers by adding the following to a .clangd
file in the project root:
If:
PathMatch: .*\.h
CompileFlags:
Add: [-xc++-header]
Clangd does have some heuristics to classify .h
files as C++, e.g. if there is a file with the same name but a .cpp
extension next to it, it will treat the .h
file as C++. There are plans to expand this heuristic to consider actual inclusion relationships in the project (i.e. treat an .h
file as C++ if any .cpp
file in the project includes it), but until then one of the above two workarounds may be necessary.
Upvotes: 1