Library not found if called in different line in sketch

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

Compiles here.

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:

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