Skip to content

Add compiler options and includes to .clangd file #543

@ghentschke

Description

@ghentschke

Users of CDT manged build projects sometimes complain that includes are not always found by clangd. Especially if the project has not been build yet or a new header file has not been included in a source file (entries in compile_commands.json are only made for .c/.cpp files). The Drivers (--query-driver) entry in the workspace preferences under C/C++ --> Editor (LSP) --> clangd, allows clangd to determine the compilers system includes:
But this may fail for projects which use a different compiler.

This approach uses the CDT managed project builds settings and writes them in the project specific .clangd file in the project root directory.
This has the advantage, that clangd uses the project specific build/compile options as a fallback if the info cannot be fetched from a compile_commands.json file. This should make the whole user experience more robust. See also #521, #518, #511 and #492.

For example, these settings:

Image Image

Would lead to a .clangd file that could look like this:

CompileFlags:
  # When using clangd update this entry to point at the desired
  # configuration directory to pick up the compile_commands.json
  CompilationDatabase: build/default
  Add: [
    -O0, 
    -g3,
    -Wall,
    -fmessage-length=0,
    -IC:/Daten/msys64/mingw64/include,
    -IC:/Daten/msys64/mingw64/include/c++/15.2.0,
    -IC:/Daten/msys64/mingw64/include/c++/15.2.0/backward,
    -IC:/Daten/msys64/mingw64/include/c++/15.2.0/x86_64-w64-mingw32,
    -IC:/Daten/msys64/mingw64/libgcc/x86_64-w64-mingw32/15.2.0/include,
    -IC:/Daten/msys64/mingw64/libgcc/x86_64-w64-mingw32/15.2.0/include-fixed
  ]

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions