PlatformIO Community

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”
#endif

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

plaformio.ini

[env:uno]
platform = atmelavr
board = uno
framework = arduino
lib_ldf_mode = deep+
lib_deps = MySensors

main.cpp

#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": [
                "/home/seb/Documents/Dev/ChambreSensor/include",
                "/home/seb/Documents/Dev/ChambreSensor/src",
                "/home/seb/Documents/Dev/ChambreSensor/.pio/libdeps/uno/MySensors_ID548",
                "/home/seb/.platformio/packages/framework-arduinoavr/cores/arduino",
                "/home/seb/.platformio/packages/framework-arduinoavr/variants/standard",
                "/home/seb/.platformio/packages/framework-arduinoavr/libraries/__cores__/arduino/EEPROM/src",
                "/home/seb/.platformio/packages/framework-arduinoavr/libraries/__cores__/arduino/HID/src",
                "/home/seb/.platformio/packages/framework-arduinoavr/libraries/__cores__/arduino/SPI/src",
                "/home/seb/.platformio/packages/framework-arduinoavr/libraries/__cores__/arduino/SoftwareSerial/src",
                "/home/seb/.platformio/packages/framework-arduinoavr/libraries/__cores__/arduino/Wire/src",
                "/home/seb/.platformio/packages/tool-unity",
                ""
            ],
1 Like

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

#ifdef __linux__
#include "SerialPort.h"
#endif

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