Include not found

I am a new user of Platform IO with Visual studio code.
I have installed the MySensors library using the library manager, and added in my project

lib_ldf_mode = deep+ ;I also tried chain, chain+, deep+
lib_deps = MySensors

In my main.cpp, I include “MySensors.h” and the following error is notified “cannot open source file “SerialPort.h” (dependency of “MySensors.h”)C/C++(1696)”
But no error during compilation.

This error is only detected when I define “#define MY_RS485”

In MySensors.h, I found

#if defined(MY_RS485)
#include “hal/transport/RS485/MyTransportRS485.cpp”

MyTransportRS485.cpp includes SerialPort.h

In MySensors dir install , I have

  • ./MySensors.h
  • ./hal/transport/RS485/MyTransportRS485.cpp
  • ./drivers/Linux/SerialPort.h

Is it expected to have SerialPort not found? a bug ? something missing in my project?

Thanks for your help

Please provide your platformio.ini and main.cpp file as well as the full output of the build task so we can reproduce it.

1 Like


platform = atmelavr
board = uno
framework = arduino
lib_ldf_mode = deep+
lib_deps = MySensors


#include <Arduino.h>

#define MY_RS485
#define MY_RS485_DE_PIN 2
#define MY_RS485_BAUD_RATE 9600

#include <MySensors.h>

void setup() {

void loop() {

Thanks for the complete and minimal example. However, it works without a problem on my machine.

Where is the error message shown? Does it appear as a tooltip when hover over red squiggly lines in the source code editor? If so, can you show a screenshot of the Visual Studio Code extension you have installed?

1 Like

Screenshot of the extensions installed:

Screenshot with the error

None of the extensions looks suspicious. The main point is to restrict C/C++ extensions to the PlatformIO IDE extension and the C/C++ extension from Microsoft.

Can you first try the following steps to see if it makes any difference:

  • Delete the .pio folder in your project directory
  • Build the project

If it doesn’t fix it, can you compare the include paths in .vscode/c_cpp_properties.json with the following extract and check that the same paths are listed:

            "includePath": [

I think this is a linux-specific issue - probably exposed by the

#ifdef __linux__
#include "SerialPort.h"

reference in MySensors_ID548/hal/transport/RS485/MyTransportRS485.cpp. The file does exist at MySensors_ID548/drivers/Linux/SerialPort.h but doesn’t seem to be needed, but IntelliSense seems to be having trouble working down the pre-processor macro chain… i.e. after opening a few of the includes along the way… it’s no longer whining about SerialPort.h and now that it can’t open ‘string’… Anyway… unless this was code for the Raspberry Pi… You should be fine to ignore this errant IntelliSense warning.

I have deleted the .pio as suggested by manuel but still same issue. Also my include paths are the same than listed.

Anyway, I will ignore this intelisense error, it doesn’t matter.

Thanks again for your help and attention

I have the same problem, but following your steps to delete .pio and rebuild does not fix the red wavy line issue

Is the project building successfully in PlatformIO? → Use Ctrl+Shift+P → Rebuild IntelliSense to fix it.
If it is not building then there is a real problem. Please then open a new topic with all the details (platformio.ini, used code).


vscode After I added the library about TFT_eSPI from platformio libraries, main.There was an issue with header files showing red squiggly lines in c, and I restarted vscode and didn’t solve the problem.

You are using the TFT_eSPI library presumably from

which strictly declares compatibility with only the Arduino framework. You are attempting to use it with the ESP-IDF framework. This will not work, it needs the Arduino libraries.

The only way this can possible work is if you use the “ESP-IDF plus Arduino-ESP32 as a component” framework method as shown in this example. Otherwise you need to find a library that is compatible with only ESP-IDF and has no dependencies to Arduino.

You can also force the library compatibility check to be off, see docs with lib_compat_mode = off, but since the Arduino headers are probably not there in your project, this will run into a compilation failure.

1 Like