Skip to content

Constant include errors with ClangD and generated compile_commands.json #4684

@jiriks74

Description

@jiriks74

What kind of issue is this?

Configuration

Operating system: KDE Neon 5.27

PlatformIO Version: 6.1.7

Description of problem

ClangD includes either system header files or doesn't see them at all.

If you include Arduino.h you'll get this error if you don't have gcc-multilib installed on your system:
clang: 'bits/libc-header-start.h' file not found [pp_file_not_found].

If you do have gcc-multilib on your system then you'll get this error instead:
clang: In included file: 'avr/pgmspace.h' file not found [pp_file_not_found].

When looking into the Arduino.h file I can see that eg. the bits/libc-header-start.h is from the system header files instead of the Arduino ones:

Image

image

Steps to Reproduce

  1. pio project init --board uno
  2. touch src/main.cpp
  3. Open main.cpp
  4. Add #include <Arduino.h> and see the error
  5. pio run -t compiledb
  6. If present from the start create some header file in the include directory and do the same as in main.cpp

Expected Results

ClangD correctly solving header paths so the code completion works

If problems with PlatformIO Build System:

The content of platformio.ini:
; PlatformIO Project Configuration File
;
;   Build options: build flags, source filter
;   Upload options: custom upload port, speed and extra flags
;   Library options: dependencies, extra library storages
;   Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html

[env:uno]
platform = atmelavr
board = uno
framework = arduino

Source file to reproduce issue:

#include <Arduino.h>

Additional info

While writing this issue I figured out that it works as expected if you first run pio project init --board uno && pio run -t compiledb and then create the main.cpp file with #include <Arduino.h>. If you do it the other way around or you run pio run -t compiledb after creating the main.cpp file you'll get these errors.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions