Need help setting up / configuring clangd extension

I am using clangd extension on VSCodium for embedded development(STM32). The workflow involves GNU Make and arm-none-eabi-gcc as compiler.

I use compiledb to generate compile_commands.json file. While it works fine for libraries included in the project folder, system libraries are not properly recognised. For example I can’t include stdio.h. Headers like stdint and tgmath.h point to default clang directory instead of the one in arm-none-eabi directory (basically doesn’t point to right header files).

While it compiles just fine using make, I am not getting auto completions and suggestions for functions like printf, sprintf etc and, even including stdio.h displays ‘file not found’ errors in editor.

How exactly do you configure clangd? I have previously used ms-cpp-tools extension on VSCode (this extension does not work on VSCodium due to microsoft license restrictions), and on there you just add a c_cpp_configuration.json file and specify things like “intellisense-mode”(eg, linux-gcc, arm-gcc etc), “compiler-path”, " c-standard" etc. It then properly finds the header files for specified compiler.

Is there a similar configuration possible for clangd?

Have you tried this? https://clangd.llvm.org/troubleshooting#cant-find-standard-library-headers-map-stdioh-etc

Hi! I came across the same issue today (clangd can’t find string.h and stdio.h), when I was trying to set up an environment for STM32 with arm-none-eabi-gcc toolchain.
In my case, I am on Arch Linux with 3 cross-compilng packages (arm-none-eabi-gcc/gdb/binutils) installed, and after some probing I finally noticed that these packages do not ship string.h, among other headers. Since I’m quite new to compiler systems, I’m not sure why this confusing behavior is the actual case.
Installing arm-none-eabi-newlib brings in the required header files at /usr/arm-none-eabi/include.
Finally, edit .clangd to include the following compiler flags:

CompileFlags:
  Add: [-I/usr/arm-none-eabi/include]

And clangd will pick up /usr/arm-none-eabi/include/stdio.h correctly.

Reference: [SOLVED] arm-none-eabi header pakage missing / AUR Issues, Discussion & PKGBUILD Requests / Arch Linux Forums


The above configuration appears to work properly in my setup. Please correct me if I’m doing anything wrong.