LDF keeps excluding library if it contains "Arduino.h"

I am facing a really strange behavior of the platformio build chain, especially with the LDF.
I was working on a project based on the stm32cube framework, so really no Arduino code needed and wanted here. But at the same time, im writing a library for some external components i need to interact with. To make my life easier, I wrote the library platform independend and use the preprocessor to change between platform dependend code.
And there “Arduino.h” comes into play. Wherever I include the Arduino Header, the matching library gets kicked out of the include path (c_cpp_properties.json) on the compilation fails, even if the “Arduino.h” isn’t used for the compilation. I tested it with a fresh stm32cube based project (with nucleo_l031k6 as board) that looked like this:
main.cpp

#include "main.hpp"
#include "Debug.hpp"
int main() {}

lib/Debug/Debug.hpp

#ifndef DEBUG
#define DEBUG

#ifdef FALSE
#include "Arduino.h"
#endif

#endif

lib/Debug/Debug.cpp

#include "Debug.hpp"

This results in:

fatal error, Debug.hpp: No such file or directory

Note, FALSE is not defined, it compiles fine if i comment out the #include “Arduino.h”
I Tried to change the LDF mode to deep+ and chain+ but the result was still the same.
Am i doing something wrong?

I don’t think you’re doing anything wrong, it seems to be a bug in how the LDF is working… as it is trying to include the library even though it’s wrapped in a proprocessor check which should not be active.

I tried this on my system, and I can see the following happening:

  1. when #include "Arduino.h"(and FALSE is not set) is commented out, the Dependency Graph lists Debug as a dependency of the project, and compile is successful.
  2. when #include "Arduino.h" (and FALSE is not set) is not commented out, the Dependency Graph does not list Debug as a dependency of the project, and compile fails, saying the debug.hpp header is missing… when it is plainly not the case. The true error is Arduino.h does not exist, and it shouldn’t be processing that include anyway!

This was regardless of the name of the library files… (i.e. debug, bug, etc)… processor macro used… (i.e. FALSE, USE_ARDUINO)… and LDF mode (i.e. default, chain+, deep+). So entirely repeatable, and seems to be a bug. And it seems to revolve about the “Arduino.h” library… as if you substitute #include "Arduino.h" for something random like #include "bubkiss.h" (which, surprise, surprise, also doesn’t exist)… and… it happily compiles?!

I’m not sure if a bug report should be placed against the stm32cube framework, or the platformio core, as this seems to be a LDF bug… @ivankravets ?

Could you provide a simple project to reproduce this issue?

This should do the trick… regardless of the status of the USE_ARDUINO flag in main.cpp, it seems that #include "Arduino.h" is being processed

Dang… pfeerick. You are fast! I just tried your code an it is exactly behaviour I was facing.

1 Like

lol… I just had to work out the best way to make it available… as I had that code from repo’ing the issue a few days ago. Was going to use a github gist until I realised it wouldn’t let me do folders… :frowning: so a repo with branches it is…