I recently switched from ctags to clangd for better lsp support in neovim. Now clangd doesn't recognize my local include directories.
I tried the following .clangd files without success (with the first one at least the macros worked which is something)
CompileFlags:
Add:
- -I./include
- -I./lib
- -D_GNU_SOURCE
- -DSHELL="/bin/sh"
CompileFlags:
Add: [-D_GNU_SOURCE, -DSHELL="/bin/sh", -I./include, -I./lib]
the .clangd file is at the project root, but it just won't work. What gives?
clangd does not support relative paths in CompileFlags
; see https://github.com/clangd/clangd/issues/1038.
The proper solution apparently is to use a compile_flags.txt
or compile_commands.json
file.
Related posts on Stack Overflow (where answers recommend to use CompileFlags
in .clangd
, they seem to neglect to mention that this only works for absolute paths):