PlatformIO ignores #ifdef Includes

Hallo together,
i have following problem.
After a Update for Platformio the #include “file” in preprocessor #ifdef get ignored.

#ifndef DeviceDefinition_H
#define DeviceDefinition_H
#include "Arduino.h"

#define USE_MCP23017

#ifdef USE_MCP23017     
    #include "MCP23017.h"
    MCP_23017Class Device;
#endif
#ifdef USE_Gateway
    #include "Gateway.h"
    GatewayClass Device;
#endif
#ifdef USE_PCA9685   
    #include "PCA9685.h"
    PCA9685Class Device;
#endif
#endif    

Befor the update all works fine. But now it throw a “no such file” error message. If i define the Class
outside the #ifdef it works again.

I tryed to clean the project, deleted the .pio folder, changed lib_ldf_mode from chain+ to deep+.

But nothing helped.

Does anyone have the same troubles?

Thanks for help :slight_smile:

Can you post the exact error? Is it a compiler error or a VSCode intellisense error? If it’s a compiler error, what’s the full log?

------------------------------------------------------------------------------------------------------------------------------------- 
----------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/espressif32/esp32dev.html
PLATFORM: Espressif 32 1.12.0 > Espressif ESP32 Dev Module
HARDWARE: ESP32 240MHz, 320KB RAM, 4MB Flash
DEBUG: Current (esp-prog) External (esp-prog, iot-bus-jtag, jlink, minimodule, olimex-arm-usb-ocd, 
olimex-arm-usb-ocd-h, olimex-arm-usb-tiny-h, olimex-jtag-tiny, tumpa)
PACKAGES:
 - framework-arduinoespressif32 3.10004.200129 (1.0.4)
 - tool-esptoolpy 1.20600.0 (2.6.0)
 - toolchain-xtensa32 2.50200.80 (5.2.0)
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain+, Compatibility ~ soft
Found 35 compatible libraries
Scanning dependencies...
Dependency Graph
|-- <ArduinoJson> 6.11.0
|-- <Dictionary>
|   |-- <ArduinoJson> 6.11.0
|-- <SPIFFS> 1.0
|   |-- <FS> 1.0
|-- <FS> 1.0
|-- <GlobalFunction>
|   |-- <Dictionary>
|   |   |-- <ArduinoJson> 6.11.0
|   |-- <FS> 1.0
|   |-- <ArduinoJson> 6.11.0
|   |-- <SPIFFS> 1.0
|   |   |-- <FS> 1.0
Building in release mode
Compiling .pio\build\esp32dev\src\main.cpp.o
Generating partitions .pio\build\esp32dev\partitions.bin
Archiving .pio\build\esp32dev\lib74c\libArduinoJson_ID64.a
Compiling .pio\build\esp32dev\libc99\Dictionary\Dictionary.cpp.o
Compiling .pio\build\esp32dev\lib594\FS\FS.cpp.o
Compiling .pio\build\esp32dev\lib594\FS\vfs_api.cpp.o
Compiling .pio\build\esp32dev\lib4d4\SPIFFS\SPIFFS.cpp.o
Compiling .pio\build\esp32dev\libbb3\GlobalFunction\GlobalFunction.cpp.o
lib\Dictionary\src\Dictionary.cpp: In member function 'Objects_t* 
DictionaryClass::Object_Search(uint16_t)':
lib\Dictionary\src\Dictionary.cpp:255:1: warning: control reaches end of non-void function [-Wreturn- 
type]
  }
  ^
Archiving .pio\build\esp32dev\libFrameworkArduinoVariant.a
In file included from lib\GlobalFunction\src\GlobalFunction.cpp:2:0:
lib\GlobalFunction\src\DeviceDefinition.h:9:30: fatal error: MCP23017.h: No such file or directory
 ******************************************************************
 * Looking for MCP23017.h dependency? Check our library registry!
*
* CLI  > platformio lib search "header:MCP23017.h"
* Web  > https://platformio.org/lib/search?query=header:MCP23017.h
*
******************************************************************

compilation terminated.
 *** [.pio\build\esp32dev\libbb3\GlobalFunction\GlobalFunction.cpp.o] Error 1
 Compiling .pio\build\esp32dev\FrameworkArduino\Esp.cpp.o

Thats the Error i get .

I don’t even find a reference for a library which implements MCP_23017Class. Which library do you use? Does declaring it in lib_deps help?

If not, can you share a minimal project which reproduces the problem?

Puh thats a little bit tricky.

main.cpp

 #include "Arduino.h"
 #include "GlobalFunction.h"
 void setup() {
 InitDevice();
 }
 void loop()
 { 
 }

GlobalFunction.h

#ifndef GlobalFunction_H
#define GlobalFunction_H
 void InitDevice();
#endif

GlobalFunction.cpp

#include "GlobalFunction.h"
#include "DeviceDefinition.h"
void InitDevice(){
   if(!Device.Init_Task()){
   }
}

DeviceDefinition.h

#ifndef DeviceDefinition_H
#define DeviceDefinition_H
   #include "Arduino.h"
   #define USE_MCP23017        
   #ifdef USE_MCP23017        
         #include "MCP23017.h"
         MCP_23017Class Device;
   #endif
#endif

Soo i try to explain.
There are several ESP32 and they got different Perepherie one for example the MCP23017.
In the DeviceDefinition.h i choose which perepherie the compilier have to use.
I want to have a changeble Instance of “Device.” and this worked until the newest update.
Now: if i put the #include “MCP23017.h” in “DeviceDefinition.h” befor the “#ifdef Use_MCP23017” it works all fine.

platformio.ini

[env:esp32dev]
platform = espressif32
board = esp32dev
framework = arduino
build_unflags = -std=gnu++11
build_flags = -std=gnu++17
build_unflags = -fno-rtti
upload_port = COM11
upload_resetmethod = nodemcu
monitor_port = COM11
monitor_speed =115200
;monitor_rts = 0
;monitor_dtr = 0
lib_deps =
  ArduinoJson@6.11.0
 lib_ldf_mode = chain+

Please remove a space before lib_ldf_mode

1 Like

Thanks for reply but the space only happend because of copy and paste and than format the code in the reply message editor.
Strange is the following.

I bind in the “Device” library in the DeviceDefinition.h. (wich is part of the GlobalFunction Folder)
If i choose the Gateway.h wich is befor the GlobalFunction folder than it works, but if i choose the MCP23017.h or PCA9685 than is get the error.
Unbenannt

Thanks and a nice weekend.