I am trying to solve a problem involving compiling identical code to either use EthernetClient or WiFiClient on arduino-esp32.
I wrote two sets of source files for EthernetClient and WiFiClient, that will
#define CLIENTTYPE to either EthernetClient or WiFiClient and then include the core file proper that has CLIENTTYPE for the client data type. The files are looking like this (Ethernet variant shown here):
#ifndef _MODBUS_SERVER_ETHERNET_H #define _MODBUS_SERVER_ETHERNET_H #include <Ethernet.h> #define CLIENTTYPE EthernetClient #include "ModbusServerTCP.h" #endif
The inner source is protected by
#endif against compilation without the wrapper files including them.
The problem now arises if I will compile a program using this - say, we are to use the EthernetClient variant, then main.cpp will do a
#include "ModbusServerEthernet.h" and most likely a #include <Ethernet.h>`` as well. The compile then will fail with
fatal error: Wifi.h: No such file or directory
for the file ModbusServerWiFi.h, where the line
#include <Wifi.h> is to be found. But why does that happen?
If I add the
#include <Wifi.h> to the main.cpp file, compile will run fine.
If I use the full path to the Wifi.h file, it works as well (
#include <C:\Users\Micha\.platformio\packages\framework-arduinoespressif32\libraries\WiFi\src\WiFi.h>) .
It looks like PlatformIO is forgetting about the include paths in this constellation.