Windows 10
IDE 2.0.0 rc9.2 installed using the zip file
Target board Nano
Library added to sketch using Sketch/Include Library
This will not compile
#include <EEPROM.h>
#include <SoftwareSerial.h>
SoftwareSerial SIM(2, 4); //Rx, Tx
const byte buttonPin = A3;
void setup()
{
SIM.begin(9600);
Serial.begin(115200);
pinMode(buttonPin, INPUT_PULLUP);
}
void loop()
{
if (digitalRead(buttonPin) == LOW)
{
sendSMS();
}
}
void readReply()
{
delay(50);
while (SIM.available())
{
Serial.write(SIM.read());
delay(50);
}
}
void sendSMS()
{
Serial.println("sending SMS");
delay(1000);
SIM.println("AT");
readReply();
delay(1000);
SIM.println("AT+CMGF=1"); //SMS mode
delay(1000);
readReply();
delay(1000);
SIM.println("AT+CMGS=\"+44nnnnnnnnnn\""); //target phone needs quotes
delay(1000);
readReply();
SIM.println("message text line 1"); //the actual message
SIM.print("message text line 2"); //the actual message
delay(1000);
readReply();
SIM.write((byte)0x1A); //^Z end of message
delay(1000);
readReply();
}
Using board 'nano' from platform in folder: C:\Users\Bob2\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.5
Using core 'arduino' from platform in folder: C:\Users\Bob2\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.5
Detecting libraries used...
"C:\\Users\\Bob2\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\avr-gcc\\7.3.0-atmel3.6.1-arduino7/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10607 -DARDUINO_AVR_NANO -DARDUINO_ARCH_AVR "-IC:\\Users\\Bob2\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.8.5\\cores\\arduino" "-IC:\\Users\\Bob2\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.8.5\\variants\\eightanaloginputs" "C:\\Users\\Bob2\\AppData\\Local\\Temp\\arduino-sketch-6FAAAA248800183E3586167950FB37F0\\sketch\\send_text_1.ino.cpp" -o nul
C:\Users\Bob2\Documents\Arduino\SIM800\send_text_1\send_text_1.ino:1:10: fatal error: EEPROM.h: No such file or directory
#include <SoftwareSerial.h>
^~~~~~~~~~
compilation terminated.
Alternatives for SoftwareSerial.h: [EspSoftwareSerial@6.13.2 espsoftwareserial-master@1.0 SoftwareSerial@1.0]
ResolveLibrary(SoftwareSerial.h)
-> candidates: [EspSoftwareSerial@6.13.2 espsoftwareserial-master@1.0 SoftwareSerial@1.0]
"C:\\Users\\Bob2\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\avr-gcc\\7.3.0-atmel3.6.1-arduino7/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10607 -DARDUINO_AVR_NANO -DARDUINO_ARCH_AVR "-IC:\\Users\\Bob2\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.8.5\\cores\\arduino" "-IC:\\Users\\Bob2\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.8.5\\variants\\eightanaloginputs" "-IC:\\Users\\Bob2\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.8.5\\libraries\\SoftwareSerial\\src" "C:\\Users\\Bob2\\AppData\\Local\\Temp\\arduino-sketch-6FAAAA248800183E3586167950FB37F0\\sketch\\send_text_1.ino.cpp" -o nul
Alternatives for SoftwareSerial.h: [EspSoftwareSerial@6.13.2 espsoftwareserial-master@1.0 SoftwareSerial@1.0]
ResolveLibrary(SoftwareSerial.h)
-> candidates: [EspSoftwareSerial@6.13.2 espsoftwareserial-master@1.0 SoftwareSerial@1.0]
Multiple libraries were found for "SoftwareSerial.h"
Used: C:\Users\Bob2\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.5\libraries\SoftwareSerial
Not used: C:\Users\Bob2\Documents\Arduino\libraries\EspSoftwareSerial
Not used: C:\Users\Bob2\Documents\Arduino\libraries\espsoftwareserial-master
Using library SoftwareSerial at version 1.0 in folder: C:\Users\Bob2\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.5\libraries\SoftwareSerial
exit status 1
Compilation error: EEPROM.h: No such file or directory
but this does - note the relative positions of the #includes
#include <SoftwareSerial.h>
#include <EEPROM.h>
SoftwareSerial SIM(2, 4); //Rx, Tx
const byte buttonPin = A3;
void setup()
{
SIM.begin(9600);
Serial.begin(115200);
pinMode(buttonPin, INPUT_PULLUP);
}
void loop()
{
if (digitalRead(buttonPin) == LOW)
{
sendSMS();
}
}
void readReply()
{
delay(50);
while (SIM.available())
{
Serial.write(SIM.read());
delay(50);
}
}
void sendSMS()
{
Serial.println("sending SMS");
delay(1000);
SIM.println("AT");
readReply();
delay(1000);
SIM.println("AT+CMGF=1"); //SMS mode
delay(1000);
readReply();
delay(1000);
SIM.println("AT+CMGS=\"+44nnnnnnnnnn\""); //target phone needs quotes
delay(1000);
readReply();
SIM.println("message text line 1"); //the actual message
SIM.print("message text line 2"); //the actual message
delay(1000);
readReply();
SIM.write((byte)0x1A); //^Z end of message
delay(1000);
readReply();
}
Both versions compile OK on IDE 1.8.13
I have tried to create the problem using a minimal sketch but have not been able to make it fail
Thanks for trying it. Still no joy here
Which version of 2.0 do you have and how was it installed ? I used the .zip download and just unzipped it into a folder and am using it from there
Same as you; RC9.2 zip, Win10 Home. "Installed" in the Downloads folder.
Same here. Compiles with only one warning:
C:\Users\Willem\AppData\Local\Arduino15\packages\MiniCore\hardware\avr\2.1.3\libraries\EEPROM\src/EEPROM.h:145:20: warning: 'EEPROM' defined but not used [-Wunused-variable]
static EEPROMClass EEPROM;
^~~~~~
Running "arduino-ide_nightly-20220819 (RC9.2) zip "installed" on F: (my only small SSD - speeds up initial start a lot) using Windows 10 Pro.
EDIT: The above was as a 328 using MiniCore. I redid it as a Nano and got the following additional warnings:
C:\Users\Willem\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.5\cores\arduino\new.cpp: In function 'void* operator new(std::size_t, std::nothrow_t)':
C:\Users\Willem\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.5\cores\arduino\new.cpp:59:60: warning: unused parameter 'tag' [-Wunused-parameter]
void * operator new(std::size_t size, const std::nothrow_t tag) noexcept {
^~~
C:\Users\Willem\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.5\cores\arduino\new.cpp: In function 'void* operator new [](std::size_t, const std::nothrow_t&)':
C:\Users\Willem\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.5\cores\arduino\new.cpp:68:63: warning: unused parameter 'tag' [-Wunused-parameter]
void * operator new[](std::size_t size, const std::nothrow_t& tag) noexcept {
^~~
C:\Users\Willem\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.5\cores\arduino\new.cpp: In function 'void operator delete(void*, const std::nothrow_t&)':
C:\Users\Willem\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.5\cores\arduino\new.cpp:103:55: warning: unused parameter 'tag' [-Wunused-parameter]
void operator delete(void* ptr, const std::nothrow_t& tag) noexcept {
^~~
C:\Users\Willem\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.5\cores\arduino\new.cpp: In function 'void operator delete [](void*, const std::nothrow_t&)':
C:\Users\Willem\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.5\cores\arduino\new.cpp:106:57: warning: unused parameter 'tag' [-Wunused-parameter]
void operator delete[](void* ptr, const std::nothrow_t& tag) noexcept {
^~~
It did, however, compile.
Sketch uses 3720 bytes (12%) of program storage space. Maximum is 30720 bytes.
Global variables use 393 bytes (19%) of dynamic memory, leaving 1655 bytes for local variables. Maximum is 2048 bytes.
Unfortunately I also was unable to reproduce this, using the same version and variant of the IDE.
@UKHeliBob please post the contents of the .cpp
file generated by the Arduino sketch preprocessor.
You can find the location in the verbose output. For example, in the output you posted above, I can see it here:
Maybe the code was corrupted in some way by the sketch preprocessor. I notice that it is referencing the wrong line in this error message:
The sketch compiles OK now either when download it from my original post or loaded from disk
I did have one failure when experimenting with the position of the #include just now but cannot nail down how to reproduce it. Unless/until I can reproduce the problem then there will be nothing to follow up
Should I get it to fail again then I will post the .cpp file as requested
Thanks all for looking
1 Like
I just stumbled across this topic and though I should add a note that we finally figured out how to reproduce this, which allowed the creation of an actionable formal bug report:
opened 04:49PM - 23 Jul 24 UTC
topic: code
type: imperfection
### Describe the problem
An Arduino IDE editor tab can be in one of two state… s:
- **Saved**: the contents of the file on disk matches the content in the editor buffer
- The editor will always be in this state if the "**Auto save**" feature is enabled.
- **Dirty**: the contents of the file on disk differs from the content staged in the editor buffer.
- This is indicated by the presence of a ⬤ at the right side of the editor tab.
Regardless of the state, when a compilation is triggered, it is the code in the editor buffer that must be compiled.
At the start of the sketch compilation process, Arduino CLI performs a "library discovery" procedure, where the preprocessor is run tentatively on the sketch program repeatedly. If preprocessing fails, Arduino CLI parses the text of the error message. If it is a "`No such file or directory`" error from an `#include` directive, the header filename is extracted from that directive and the searches installed libraries are searched to find the one that provides that header file. The library is added to the compiler's ["search path"](https://gcc.gnu.org/onlinedocs/cpp/Search-Path.html), then the process repeated until either the preprocessing passes, or else a library can't be discovered for an `#include` directive (see [the flowchart](#library-discovery-overview) in the "**Additional context**" section of the issue if this isn't clear).
🐛 Sketch compilation fails if the sketch code staged in the editor buffer differs from the file on disk in a way that causes one `#include` directive to be present in the staged code at the line number of a different `#include` directive in the file on disk.
### To reproduce
1. Select **File > Preferences** from the Arduino IDE menus.
1. Uncheck the box next to "**Auto save**".
1. Click the "**OK** button.
1. Select **File > New Sketch** from the Arduino IDE menus.
A new sketch will open in an Arduino IDE window.
1. Change the sketch code to the following:
```cpp
#include <EEPROM.h>
#include <SPI.h>
#include <SoftwareSerial.h>
#include <Wire.h>
void setup() {}
void loop() {}
```
**ⓘ** The fault will occur with any sketch that contains multiple consecutive `#include` directives.
1. Select **File > Save As...** from the Arduino IDE menus.
1. Save the sketch to any convenient location.
1. Select **Tools > Board > Arduino AVR Boards > Arduino Uno** from the Arduino IDE menus.
**ⓘ** The fault will occur with any board. The "Arduino Uno" was picked arbitrarily for the sake of the demonstration.
1. Select **Sketch > Verify/Compile** from the Arduino IDE menus.
🙂 The sketch compiles without errors.
1. Add a blank line at the top of the sketch.
❗ Do not save the sketch. It must be in a "dirty" state to reproduce the fault.
1. Select **Sketch > Verify/Compile** from the Arduino IDE menus.
🐛 Compilation fails spuriously:
```text
C:\Users\per\Documents\Arduino\Foo\Foo.ino:2:10: fatal error: EEPROM.h: No such file or directory
#include <SPI.h>
^~~~~~~
```
**ⓘ** Note that the `#include` directive for `EEPROM.h` is at line 1 in the file on disk, while it is at line 2 in the staged code, which is the position of the `#include` directive for `SPI.h` in the file on disk.
1. Add another blank line at the top of the sketch.
❗ Do not save the sketch. It must be in a "dirty" state to reproduce the fault.
1. Select **Sketch > Verify/Compile** from the Arduino IDE menus.
🐛 Compilation fails spuriously:
```text
C:\Users\per\Documents\Arduino\Foo\Foo.ino:2:10: fatal error: EEPROM.h: No such file or directory
#include <SoftwareSerial.h>
^~~~~~~~~~
```
1. Add another blank line at the top of the sketch.
❗ Do not save the sketch. It must be in a "dirty" state to reproduce the fault.
1. Select **Sketch > Verify/Compile** from the Arduino IDE menus.
🐛 Compilation fails spuriously:
```text
C:\Users\per\Documents\Arduino\Foo\Foo.ino:2:10: fatal error: EEPROM.h: No such file or directory
#include <Wire.h>
^~~~~~~~
```
1. Add another blank line at the top of the sketch.
1. Select **Sketch > Verify/Compile** from the Arduino IDE menus.
🙂 The sketch compiles without errors.
**ⓘ** Note that the `#include` directive for `EEPROM.h` is at line 1 in the file on disk, while it is at line 5 in the staged code, which is the position of the `setup` function definition in the file on disk.
### Expected behavior
Library discovery always works correctly, even when a sketch is in a "dirty" state.
### Arduino IDE version
aa9b10d
### Operating system
Windows
### Operating system version
- Windows 10
- Windows 11
### Additional context
The fault does not occur if the sketch is not in a "dirty" state when compiled, whether the non-dirty state is achieved by the IDE's auto save, or by saving manually.
---
Blank lines were added in the demo for the sake of simplicity, but the fault occurs regardless of what the content of the added line is.
<a name="workaround"></a>
#### Workaround
Select **File > Save** from the Arduino IDE menus.
<a name="library-discovery-overview"></a>
#### Library discovery overview
In case the text description of library discovery provided in the introduction is not clear, this flowchart might make it easier to understand:
```mermaid
%%{
init: {
'flowchart': {
'curve': 'monotoneY'
},
'theme': 'base',
'themeVariables': {
'clusterBkg': '#ffffff',
'edgeLabelBackground': '#ffffff',
'lineColor': '#000000',
'primaryBorderColor': '#000000',
'primaryColor': '#f0f0f0',
'primaryTextColor': '#000000'
}
}
}%%
flowchart TB
subgraph main[" "]
direction TB
compileCommand(["<code>compile</code><br />command"])
selectSketchFile[/"Select unprocessed<br />sketch file"/]
done{"All<br />processed?"}
preprocess[/"C++ preprocess"/]
preprocessorError{"Error?"}
parseError[/"Parse error<br />message"/]
includeError{"<code>#include</code><br />error?"}
headerAvailable{"A library<br />provides<br />header?"}
addToSearchPath["Add library<br />to search path"]
compile[["Compilation"]]
failure(["Error"])
compileCommand --> selectSketchFile
selectSketchFile --> done
done -- "Yes" --------> compile
done -- "No" --> preprocess
preprocess --> preprocessorError
preprocessorError -- "Yes" --> parseError
parseError --> includeError
includeError -- "Yes" --> headerAvailable
headerAvailable -- "Yes" --> addToSearchPath
addToSearchPath --> preprocess
preprocessorError -- "No" --> selectSketchFile
includeError -- "No" ----> failure
headerAvailable -- "No" --> compile
end
```
#### Additional reports
- https://forum.arduino.cc/t/ide-2-1-bug-i-m-only-adding-a-new-blank-line/1144525
- https://forum.arduino.cc/t/ide-2-2-1-possible-compiler-bug/1208608
- https://forum.arduino.cc/t/blank-lines-inserted-at-start-of-sketch-causes-library-errors/1283385
- https://forum.arduino.cc/t/library-not-found-if-called-in-different-line-in-sketch/1023831
### Issue checklist
- [X] I searched for previous reports in [the issue tracker](https://github.com/arduino/arduino-ide/issues?q=)
- [X] I verified the problem still occurs when using the latest [nightly build](https://www.arduino.cc/en/software#nightly-builds)
- [X] My report contains all necessary details
Thanks for your report UKHeliBob. I'm sorry we weren't able to effectively act on it, but I guess better late than never.
Thanks for the feedback. I had long ago forgotten about the problem
1 Like