IDE 2.2.1 Possible Compiler Bug?

It's ok, I figured out what you meant!

My own 'solution' of moving the #includes above the comments just broke again :thinking:.

This time I had to add a #define before the first #include and I got the No such file or directory error again. I had to put the new #define later in the code.

The sketch code does not go directly to the compiler, but is run through a preprocesses step first. What does the code look like after the preprocess step? Maybe it is generating something that is confusing the compiler.

Look at the end of the listing for the temporary directory that was created and find the output in the preproc subdirectory.

1 Like

@oldcurmudgeon of course you're correct. It's probably something that the preprocessor is doing that's messing things up. In a post above I showed that a diff of the .cpp files: the 'good' one which compiles fine and the 'bad' one (with the missing file error) showed the only difference was the bad file is missing all the function prototypes that the preprocessor kindly adds for us. As to why they are missing, I've not a clue!

I am fairly sure the error is somewhere in the Arduino preprocessor.

I used to know my way around a bit in the IDE 1.x code, but I am not familiar with the IDE 2.x code. I haven't found the code for the preprocessor yet, I will keep looking!

@bobcousins Hi Bob. I couldn't find the preproc subdirectory that @oldcurmudgeon mentioned in their reply above. I did have the verbose option ticked but the only human-readable files I could find was the .cpp file and a cpp.d.

It is done for Arduino IDE 2.x by the Arduino CLI helper tool, so you must look in that codebase:

Arduino CLI also uses ctags to parse the code for this process. The version of ctags used by Arduino is here:

1 Like

So I think I have a MCVE example code that reproduces the bug consistently. The code as-is below verifies/compiles correctly. If you go to line 58 #include <Adafruit_GFX.h> and press return to enter a blank line before it, now verify/compile gives Compilation error: Adafruit_GFX.h: No such file or directory for this library.

It's reproducible every time. I can even quit the IDE and reload the sketch, compile it correctly, then add the blank line and the error is back.




// #define DEBUG
// #define SHOWTIMING
// #define DEBUGMODE
// #define DEBUG_EDIT_STATES
// #define DEBUG_SELECT_PARAMETER
// #define DEBUG_ENCODER
// #define DEBUG_FOOTSWITCH
// #define DEBUG_BUTTON_EVENT
// #define DEBUG_EEPROM_WRITE
// #define DEBUG_POT_WRITING
// #define DEBUG_BYPASS_SWITCH
// #define DEBUG_ANALOG_DISPLAY
// #define DEBUG_WEAR_LEVELLING
// #define DEBUG_FXC_PROGCONTROL
// #define DEBUG_POTS_SWITCH
// #define DEBUG_SENDPROG
// #define DEBUG_SEND_MREGS
// #define DEBUG_SEND_CREGS
// #define DEBUG_SEND_SFR
// #define DEBUG_FXCORE_STATUS
// #define DEBUG_ADJUST_MODE
// #define DEBUG_SERIAL_RECEIVE
// #define DEBUG_DISPLAYHEADS
// #define TEST_LEDS
// #define SHOW_LOGO
// #define SHOW_BOARD_TYPE_ON_STARTUP
// #define DEBUG_PATCHNAME_EDITING
// #define USE_PROGMEM
// #define SCAN_I2C_BUS
// #define DEBUG_CODEC_SETUP
#define USE_ILI9341_FAST_LIB
// #define MEASURE_PATCH_CHANGE_TIME
#define MUTE_DURING_PATCH_CHANGE

#define SHOW_BPM
#define SHOW_MILLIS

//#define DEBUG_MIDI_RX

//#define TEST_FXCORE_PROGRAMMING

#define UnitName "Project X"

#ifdef DEBUG
#define Version "2.13.0 Debug"
#else
#define Version "2.13.0"
#endif

/***********************************************************************************************************


************************************************************************************************************/

#include <LibPrintf.h>  // Adds a C++ style printf function. Makes outputting debugging messages to the serial monitor easier.
#include <Adafruit_GFX.h>      // Core graphics library
#include <Adafruit_ILI9341.h>  // Hardware-specific library for ILI9341 driver chip

#ifdef USE_ILI9341_FAST_LIB
#include <ILI9341_Fast.h>
#endif

// #include <Fonts/FreeMonoBold18pt7b.h>
// #include <Fonts/FreeMonoBold12pt7b.h>

#include "SPI.h"
#include "Wire.h"
#include "OneButton.h"

#include <I2C.h>

#include <MIDI.h>

MIDI_CREATE_INSTANCE(HardwareSerial, Serial1, MIDI);

// SPISettings mySPI(SPI_CLOCK_DIV2, MSBFIRST,SPI_MODE0);

#include <AceButton.h>
using namespace ace_button;

// Include EEPROM library code
#include <EEPROM.h>


// Include the rotary encoder library
#include <rotary.h>

void setup() {
  // put your setup code here, to run once:

}

void loop() {
  // put your main code here, to run repeatedly:

}

Is it really necessary to use all those 3rd party libraries to reproduce the fault? I spent some time tracking them down and installing them but finally gave up.

Thanks, I was about to ask for one.

Line 58 is a blank line? #include <Adafruit_GFX.h> is on linbe 56, perhaps you meant 56?

So far I have installed libraries from the standard list and have not encountered any unexpected errors, but I am missing "ILI9341_Fast.h" and "rotary.h", if you say where you got those.

ETA: Also I can't find "I2C.h"

Possibly it is necessary. If I take them out I don't get the error. :thinking:

Thanks for taking a look at this Bob. In the IDE my file has two blank lines before the first // #define DEBUG but it seems when the code is copied from this thread and pasted into the IDE, the blank lines are omitted. This is what I see when I copy the code from my post above (using the copy button) and paste it into a new sketch: the original two blank lines are missing.

This would explain why line 58 doesn't match!

Here's a new MCVE with all the 'non-standard' library #includes commented out. Make sure you add two blank lines at the start after you paste it into the IDE 2.2.1. The #include <Adafruit_GFX.h> // Core graphics library line should be on line 58.



// #define DEBUG
// #define SHOWTIMING
// #define DEBUGMODE
// #define DEBUG_EDIT_STATES
// #define DEBUG_SELECT_PARAMETER
// #define DEBUG_ENCODER
// #define DEBUG_FOOTSWITCH
// #define DEBUG_BUTTON_EVENT
// #define DEBUG_EEPROM_WRITE
// #define DEBUG_POT_WRITING
// #define DEBUG_BYPASS_SWITCH
// #define DEBUG_ANALOG_DISPLAY
// #define DEBUG_WEAR_LEVELLING
// #define DEBUG_FXC_PROGCONTROL
// #define DEBUG_POTS_SWITCH
// #define DEBUG_SENDPROG
// #define DEBUG_SEND_MREGS
// #define DEBUG_SEND_CREGS
// #define DEBUG_SEND_SFR
// #define DEBUG_FXCORE_STATUS
// #define DEBUG_ADJUST_MODE
// #define DEBUG_SERIAL_RECEIVE
// #define DEBUG_DISPLAYHEADS
// #define TEST_LEDS
// #define SHOW_LOGO
// #define SHOW_BOARD_TYPE_ON_STARTUP
// #define DEBUG_PATCHNAME_EDITING
// #define USE_PROGMEM
// #define SCAN_I2C_BUS
// #define DEBUG_CODEC_SETUP
#define USE_ILI9341_FAST_LIB
// #define MEASURE_PATCH_CHANGE_TIME
#define MUTE_DURING_PATCH_CHANGE

#define SHOW_BPM
#define SHOW_MILLIS

//#define DEBUG_MIDI_RX

//#define TEST_FXCORE_PROGRAMMING

#define UnitName "Project X"

#ifdef DEBUG
#define Version "2.13.0 Debug"
#else
#define Version "2.13.0"
#endif

/***********************************************************************************************************


************************************************************************************************************/

//#include <LibPrintf.h>  // Adds a C++ style printf function. Makes outputting debugging messages to the serial monitor easier.
#include <Adafruit_GFX.h>      // Core graphics library
#include <Adafruit_ILI9341.h>  // Hardware-specific library for ILI9341 driver chip

#ifdef USE_ILI9341_FAST_LIB
//#include <ILI9341_Fast.h>
#endif

// #include <Fonts/FreeMonoBold18pt7b.h>
// #include <Fonts/FreeMonoBold12pt7b.h>

#include "SPI.h"
#include "Wire.h"
//#include "OneButton.h"

//#include <I2C.h>

//#include <MIDI.h>

//MIDI_CREATE_INSTANCE(HardwareSerial, Serial1, MIDI);

// SPISettings mySPI(SPI_CLOCK_DIV2, MSBFIRST,SPI_MODE0);

//#include <AceButton.h>
//using namespace ace_button;

// Include EEPROM library code
#include <EEPROM.h>


// Include the rotary encoder library
//#include <rotary.h>

void setup() {
  // put your setup code here, to run once:

}

void loop() {
  // put your main code here, to run repeatedly:

}

It should verify/compile ok. Now place the cursor at the start of line 58 and hit return so that line 58 is now blank and the #include <Adafruit_GFX.h> // Core graphics library line moves down to line 59 and try the verify/compile again. Now we get the error:

Unfortunately I was unable to reproduce the issue with that. It might depend on the versions of libraries used.

If you could turn on verbose output (File->Preferences->Show verbose output) and post the compiler output that might reveal something.

Darn - thought that MCVE would have let you reproduce the problem Bob! The two Adafruit libs are the latest versions 1.11.9 and 1.6.0 respectively. You did put the two blank lines in at the start?

Verbose output:

FQBN: arduino:avr:mega
Using board 'mega' from platform in folder: C:\Users\Philip\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.6
Using core 'arduino' from platform in folder: C:\Users\Philip\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.6

Detecting libraries used...
C:\Users\Philip\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=atmega2560 -DF_CPU=16000000L -DARDUINO=10607 -DARDUINO_AVR_MEGA2560 -DARDUINO_ARCH_AVR -IC:\Users\Philip\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.6\cores\arduino -IC:\Users\Philip\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.6\variants\mega C:\Users\Philip\AppData\Local\Temp\arduino\sketches\ED6868466D93BB34AA173AF06A04ADF2\sketch\PreProcesorBugTest_V3.ino.cpp -o nul
Alternatives for Adafruit_ILI9341.h: [Adafruit ILI9341@1.6.0]
ResolveLibrary(Adafruit_ILI9341.h)
  -> candidates: [Adafruit ILI9341@1.6.0]
F:\Documents\Arduino\PreProcesorBugTest_V3\PreProcesorBugTest_V3.ino:59:10: fatal error: Adafruit_GFX.h: No such file or directory
 #include <Adafruit_ILI9341.h>  // Hardware-specific library for ILI9341 driver chip
          ^~~~~~~~~~~~~~~~
compilation terminated.
C:\Users\Philip\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=atmega2560 -DF_CPU=16000000L -DARDUINO=10607 -DARDUINO_AVR_MEGA2560 -DARDUINO_ARCH_AVR -IC:\Users\Philip\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.6\cores\arduino -IC:\Users\Philip\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.6\variants\mega -IF:\Documents\Arduino\libraries\Adafruit_ILI9341 C:\Users\Philip\AppData\Local\Temp\arduino\sketches\ED6868466D93BB34AA173AF06A04ADF2\sketch\PreProcesorBugTest_V3.ino.cpp -o nul
Alternatives for Adafruit_ILI9341.h: [Adafruit ILI9341@1.6.0]
ResolveLibrary(Adafruit_ILI9341.h)
  -> candidates: [Adafruit ILI9341@1.6.0]

Using library Adafruit ILI9341 at version 1.6.0 in folder: F:\Documents\Arduino\libraries\Adafruit_ILI9341 
exit status 1

Compilation error: Adafruit_GFX.h: No such file or directory

Here is the output from my compile:

Detecting libraries used...
C:\Users\bobco\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=atmega2560 -DF_CPU=16000000L -DARDUINO=10607 -DARDUINO_AVR_MEGA2560 -DARDUINO_ARCH_AVR -IC:\Users\bobco\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.6\cores\arduino -IC:\Users\bobco\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.6\variants\mega C:\Users\bobco\AppData\Local\Temp\arduino\sketches\6A778FEE61D35F27831FA5BC62F66989\sketch\sketch_jan12b.ino.cpp -o nul
Alternatives for Adafruit_GFX.h: [Adafruit GFX Library@1.11.9]
ResolveLibrary(Adafruit_GFX.h)
  -> candidates: [Adafruit GFX Library@1.11.9]
C:\Users\bobco\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=atmega2560 -DF_CPU=16000000L -DARDUINO=10607 -DARDUINO_AVR_MEGA2560 -DARDUINO_ARCH_AVR -IC:\Users\bobco\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.6\cores\arduino -IC:\Users\bobco\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.6\variants\mega -Ic:\Users\bobco\OneDrive\Documents\Arduino\libraries\Adafruit_GFX_Library C:\Users\bobco\AppData\Local\Temp\arduino\sketches\6A778FEE61D35F27831FA5BC62F66989\sketch\sketch_jan12b.ino.cpp -o nul
Alternatives for Adafruit_I2CDevice.h: [Adafruit BusIO@1.14.5]
ResolveLibrary(Adafruit_I2CDevice.h)
  -> candidates: [Adafruit BusIO@1.14.5]
C:\Users\bobco\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=atmega2560 -DF_CPU=16000000L -DARDUINO=10607 -DARDUINO_AVR_MEGA2560 -DARDUINO_ARCH_AVR -IC:\Users\bobco\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.6\cores\arduino -IC:\Users\bobco\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.6\variants\mega -Ic:\Users\bobco\OneDrive\Documents\Arduino\libraries\Adafruit_GFX_Library -Ic:\Users\bobco\OneDrive\Documents\Arduino\libraries\Adafruit_BusIO C:\Users\bobco\AppData\Local\Temp\arduino\sketches\6A778FEE61D35F27831FA5BC62F66989\sketch\sketch_jan12b.ino.cpp -o nul
Alternatives for Wire.h: [Wire@1.0]
ResolveLibrary(Wire.h)
  -> candidates: [Wire@1.0]
C:\Users\bobco\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=atmega2560 -DF_CPU=16000000L -DARDUINO=10607 -DARDUINO_AVR_MEGA2560 -DARDUINO_ARCH_AVR -IC:\Users\bobco\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.6\cores\arduino -IC:\Users\bobco\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.6\variants\mega -Ic:\Users\bobco\OneDrive\Documents\Arduino\libraries\Adafruit_GFX_Library -Ic:\Users\bobco\OneDrive\Documents\Arduino\libraries\Adafruit_BusIO -IC:\Users\bobco\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.6\libraries\Wire\src C:\Users\bobco\AppData\Local\Temp\arduino\sketches\6A778FEE61D35F27831FA5BC62F66989\sketch\sketch_jan12b.ino.cpp -o nul
Alternatives for SPI.h: [SPI@1.0]
ResolveLibrary(SPI.h)
  -> candidates: [SPI@1.0]
C:\Users\bobco\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=atmega2560 -DF_CPU=16000000L -DARDUINO=10607 -DARDUINO_AVR_MEGA2560 -DARDUINO_ARCH_AVR -IC:\Users\bobco\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.6\cores\arduino -IC:\Users\bobco\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.6\variants\mega -Ic:\Users\bobco\OneDrive\Documents\Arduino\libraries\Adafruit_GFX_Library -Ic:\Users\bobco\OneDrive\Documents\Arduino\libraries\Adafruit_BusIO -IC:\Users\bobco\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.6\libraries\Wire\src -IC:\Users\bobco\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.6\libraries\SPI\src C:\Users\bobco\AppData\Local\Temp\arduino\sketches\6A778FEE61D35F27831FA5BC62F66989\sketch\sketch_jan12b.ino.cpp -o nul
Alternatives for Adafruit_ILI9341.h: [Adafruit ILI9341@1.6.0]
ResolveLibrary(Adafruit_ILI9341.h)
  -> candidates: [Adafruit ILI9341@1.6.0]
C:\Users\bobco\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=atmega2560 -DF_CPU=16000000L -DARDUINO=10607 -DARDUINO_AVR_MEGA2560 -DARDUINO_ARCH_AVR -IC:\Users\bobco\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.6\cores\arduino -IC:\Users\bobco\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.6\variants\mega -Ic:\Users\bobco\OneDrive\Documents\Arduino\libraries\Adafruit_GFX_Library -Ic:\Users\bobco\OneDrive\Documents\Arduino\libraries\Adafruit_BusIO -IC:\Users\bobco\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.6\libraries\Wire\src -IC:\Users\bobco\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.6\libraries\SPI\src -Ic:\Users\bobco\OneDrive\Documents\Arduino\libraries\Adafruit_ILI9341 C:\Users\bobco\AppData\Local\Temp\arduino\sketches\6A778FEE61D35F27831FA5BC62F66989\sketch\sketch_jan12b.ino.cpp -o nul
Alternatives for EEPROM.h: [EEPROM@2.0]
ResolveLibrary(EEPROM.h)
  -> candidates: [EEPROM@2.0]

This is the "library detection" phase. From observation the process is :

  1. Compile the sketch without any library paths using -E (preprocess only) option.
  2. Examine the compiler output for the first unresolved #include.
  3. Look for the included name in the list of known libraries.
  4. If the file is not found, output the error message
  5. If the file is found, goto 1 but add the library path to the compile command.
  6. If there are no unresolved #includes, then detection is finished. The list of resolved library paths is used to subsequently compiler the sketch.

This process resolves all the includes in the sketch, as well as any nested includes.

In my example, you can see this progress as expected through the sketch. But your case, it seems to go wrong straight off the bat. It should be looking for Adafruit_GFX.h, but instead resolves Adafruit_ILI9341.h :

Alternatives for Adafruit_ILI9341.h: [Adafruit ILI9341@1.6.0]
ResolveLibrary(Adafruit_ILI9341.h)
  -> candidates: [Adafruit ILI9341@1.6.0]

which is not the library it was looking for, it then outputs the error which comes from the compiler "F:\Documents\Arduino\PreProcesorBugTest_V3\PreProcesorBugTest_V3.ino:59:10: fatal error: Adafruit_GFX.h: No such file or directory"

However, it goes on to repeat the compiler with the path to Adafruit_ILI9341.h added, and resolves that library again, before giving up.

So it appears the library detection is getting confused about which library it is trying to resolve.

For info, the code that does the library detection is in arduino-cli/internal/arduino/builder/internal/detector/detector.go at master ยท arduino/arduino-cli ยท GitHub. I don't get a very warm and fuzzy feeling reading the code; there are many TODOs. Some seem quite fundamental :

// TODO understand if we have to do a deepcopy

That seems a bit of "fingers crossed and hope it works" kinda thing :confused:

1 Like

I had noticed that the complier seemed to be complaining about the wrong library! It seems to totally miss the Adafruit_GFX library on the first pass.

Could it be related to dependencies in one library on the other one?

I share your concern about those TODOs :stuck_out_tongue_winking_eye: :crazy_face:

Thanks for your help (so far :slightly_smiling_face:). Maybe the 'powers that be' can have a look at some of those TODOs and see if any relate to this bug.

You can always raise an issue at Issues ยท arduino/arduino-ide ยท GitHub :wink:

I can't do it because I don't experience the issue; any follow-up questions would go to me and I can't answer them.

1 Like

@sonofcy made the important discovery that the bug only occurs when the sketch is in an unsaved state (AKA "dirty"), where the code staged in the Arduino editor does not match the code in the file stored on your hard drive.

This is likely the essential condition that was not present for those like myself who were unable to reproduce the fault. I had the "Auto save" feature enabled in my Arduino IDE preferences (it is enabled by default), which caused Arduino IDE to automatically save the sketch after I added the blank lines, thus causing the fault to not occur.

This means that the workaround for the bug is to select File > Save from the Arduino IDE menus before compiling or uploading the sketch.


The Arduino IDE developers are now tracking the bug here:

If you have a GitHub account, you can subscribe to that thread to get notifications of any new developments related to this subject:

screenshot of Subscribe button


:exclamation: Please only comment on the GitHub issue thread if you have new technical information that will assist with the resolution. General discussion and support requests are always welcome here on the Arduino Forum.


1 Like