I'm implementing an IoT device using the Espalexa library on a Wemos D1 R1 board. I wanted to make some modifications on the library code, so I copied the library files from the Arduino libraries folder to my sketch directory to perform those modifications on the copy. I changed the library header file name in order to avoid conflicts with the library (from file Espalexa.h to file Espalexamod.h), but now it won't compile, giving me this unexpected error.
First of all, by compiling using the library included as <Espalexa.h> everything works fine, while after trying to compile the following sketch:
#include "Espalexamod.h"
void setup() {
// Put your setup code here, to run once:
}
void loop() {
// Put your main code here, to run repeatedly:
}
It gives me the following, unexpected error:
C:\path\to\sketch\Espalexamod.h:610:2: error: #endif without #if
610 | #endif
| ^~~~~
exit status 1
Compilation error: #endif without #if
Specifically, this is the last #endif in the code (the one closing the guard define). I also tried changing the guard define to another name and check that all defines were closed on the code (but this was obvious since by using the library normally, everything works fine).
As a last try, I commented the #endif on the file and after compiling it gave another unexpected error
C:\bath\to\sketch\Espalexamod.h:1:1: error: '<?>' does not name a type
1 | <?>#ifndef Espalexa_h
|
exit status 1
Compilation error: stray '#' in program
where <?> is actually a diamond question mark symbol, so it seems that this time it correctly recognizes the final #endif as needed (because it's needed!).
I'm really going crazy after this. I also tried with IDE 1.x and 2.x, and I tried deleting the build cache and creating a new sketch from scratch, but nothing seems to work.
How can I fix it?
The <?> doesn't belong. That error is preventing #ifndef Espalexa_h
from being seen. So when you reach the #endif
then there was no previous if because that #ifndef
didn't get read.