0

I have tried develop Linux kernel module on vim with LSP(clangd)
But bunch of warning and errors are appeared.

It may caused by lack of clangd some configurations.

What header files and compiler parameters are required to use clangd with kernel module sources?

My compile_flags.txt is just one line but I know it's not enough:

-I/usr/lib/modules/5.19.3-arch1-1/build/include
KiYugadgeter
  • 3,796
  • 7
  • 34
  • 74

1 Answers1

1

The general recommendations around configuring projects for use with clangd are:

  1. Prefer compile_commands.json to compile_flags.txt.

    compile_flags.txt has many limitations (for example, it does not allow clangd to index the project) and is really only suitable for toy projects.

  2. Do not hand-write your compile_commands.json, generate it automatically from build system metadata.

    The way to do this is somewhat specific to your build system, but a common and versatile approach is to use bear, which wraps your build command (e.g. if you build with make, you'd run bear make), and generates compile_commands.json based on the compiler invocations made by the build command.

    See https://clangd.llvm.org/installation#project-setup for more details and more options.

I don't have specific advice for the Linux kernel; maybe others can chime in on that.

HighCommander4
  • 50,428
  • 24
  • 122
  • 194