Compiles in IDE 1.8.5 but not in IDE 1.8.7 ??

The sketch gives a compilation error message in IDE 1.8.7

‘’ was not declared in this scope.

Now, I usually get this message when some bracket } is missing or misplaced and the compiler then confuses the beginning and end of functions and therefore cannot see a certain function.

So, I spent hours trying to figure out what was wrong and I even reverted to previous versions of the sketch which got me even more confused and with no success!

I then remembered that I have an earlier version of IDE 1.8.5 installed on a virtual machine, and decided to compile the same sketch with that. Surprise: Compiles just fine.!

Anybody else had similar experience?

Possibly the Arduino builder that drops a stitch. Just a guess, but try to put a function prototype near the top of your code.

For more help, post your full code.

What do you mean by a function prototype?

In C/C++, the compiler needs to know which arguments a function takes before you can use it. That way it can check if you pass the correct types.

E.g. digitalWrite takes two unsigned 8-bit values. The prototype is defined in Arduino.h which is included by the builder before the actual compile starts.

void digitalWrite(uint8_t, uint8_t);

So if you use digitalWrite inyour code, the compiler knows what to expect and will warn you if you e.g. pass a pointer to a char instead of a byte.

So if you have a function named blink as shown below

void setup()
{
  ...
  ...
}

void loop()
{
  blink();
}

void blink()
{
  blink here
}

you should have a prototype for it before loop() as shown below; I've placed it before setup().

// prototypes
void blink();

void setup()
{
  ...
  ...
}

void loop()
{
  blink();
}

void blink()
{
  blink here
}

This is the way that the compiler expects things.

The Arduino builder does this for you but sometimes drops a stitch and puts it in the wrong place in which case you have to do it manually (as shown).

PS 1) This is what I hate about the Arduino environment; it makes either lazy programmers (e.g. me) or programmers that don't know the essentials of the language (e.g. you, no offense intended).

PS 2) Alternatively, you can move the full function to before loop() and omit the prototype as the compiler will then know what the functionneeds as arguments.

void blink()
{
  blink here
}

void setup()
{
  ...
  ...
}

void loop()
{
  blink();
}

You will need to post full code and full error message for more help.

There was a function prototype generation in arduino-builder 1.4.1, used by Arduino IDE 1.8.7 and 1.8.8. This bug has since been fixed. You could check if this is the problem you're having by testing the Arduino IDE Hourly Build: https://www.arduino.cc/en/Main/Software#hourly

you should have a prototype for it before loop() as shown below; I've placed it before setup().

Ok. I did just that. I placed a prototype of the function the compiler couldn't locate. Now it complains -same error message -about another function!

So I have to create a prototype for every single function I have in my sketch ?

Its six years now I am programing Arduino, and never came across this!

This is what I hate about the Arduino environment; it makes either lazy programmers (e.g. me) or programmers that don't know the essentials of the language (e.g. you, no offense intended).

None taken. No worries! :)

pert: There was a function prototype generation in arduino-builder 1.4.1, used by Arduino IDE 1.8.7 and 1.8.8. This bug has since been fixed. You could check if this is the problem you're having by testing the Arduino IDE Hourly Build: https://www.arduino.cc/en/Main/Software#hourly

So this bug fix hasn't been included in an official release yet?

How come it never appeared before (been using this release since day 1 it came out) and have compiled some pretty big sketches (100k compiled code on MEGA) and only just now ?

Watcher: So this bug fix hasn't been included in an official release yet?

Correct. There has been an arduino-builder release since then, which is being used in the hourly build.

Watcher: How come it never appeared before (been using this release since day 1 it came out) and have compiled some pretty big sketches (100k compiled code on MEGA) and only just now ?

The bug only occurs under very specific circumstances. Most sketches will compile just fine with Arduino IDE 1.8.7.

More information: https://github.com/arduino/Arduino/issues/8308 (and in the issues that link off that issue)

Watcher: So I have to create a prototype for every single function I have in my sketch ?

Perhaps. Keep in mind, you have to do that anyways if you were using any IDE for "non-lazy" programmers.

The other alternative is to fix the issue that's triggering the bug. You can get a feel for the things that would cause this by looking at the issues at the link above. If you want, you can post your sketch and I will take a look to see if I can spot the problematic code.

When you encounter odd errors like this, it can be very helpful to examine the post-sketch preprocessing output to see the sketch code that's actually being compiled:

  • File > Preferences
  • Check the box next to "Show verbose output during: compilation'
  • Click "OK"
  • Sketch > Verify/Compile
  • After compilation fails, scroll the black console window at the bottom of the Arduino IDE window all the way to the top.
  • Examine the first line of output to find the value of the "-build-path" option.

For example, if you had this:

C:\ArduinoIDE\arduino-nightly\arduino-builder -dump-prefs -logger=machine -hardware C:\ArduinoIDE\arduino-nightly\hardware -hardware C:\Users\per\AppData\Local\Arduino15\packages -hardware E:\electronics\arduino\hardware -tools C:\ArduinoIDE\arduino-nightly\tools-builder -tools C:\ArduinoIDE\arduino-nightly\hardware\tools\avr -tools C:\Users\per\AppData\Local\Arduino15\packages -built-in-libraries C:\ArduinoIDE\arduino-nightly\libraries -libraries E:\electronics\arduino\libraries -fqbn=esp32:esp32:node32s:FlashFreq=80,UploadSpeed=921600 -vid-pid=0X2341_0X0042 -ide-version=10809 -build-path C:\Users\per\AppData\Local\Temp\arduino_build_889992 -warnings=all -build-cache C:\Users\per\AppData\Local\Temp\arduino_cache_764477 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.esptool.path=C:\Users\per\AppData\Local\Arduino15\packages\esp32\tools\esptool\2.3.1 -prefs=runtime.tools.esptool-2.3.1.path=C:\Users\per\AppData\Local\Arduino15\packages\esp32\tools\esptool\2.3.1 -prefs=runtime.tools.mkspiffs.path=C:\Users\per\AppData\Local\Arduino15\packages\esp32\tools\mkspiffs\0.2.3 -prefs=runtime.tools.mkspiffs-0.2.3.path=C:\Users\per\AppData\Local\Arduino15\packages\esp32\tools\mkspiffs\0.2.3 -prefs=runtime.tools.xtensa-esp32-elf-gcc.path=C:\Users\per\AppData\Local\Arduino15\packages\esp32\tools\xtensa-esp32-elf-gcc\1.22.0-80-g6c4433a-5.2.0 -prefs=runtime.tools.xtensa-esp32-elf-gcc-1.22.0-80-g6c4433a-5.2.0.path=C:\Users\per\AppData\Local\Arduino15\packages\esp32\tools\xtensa-esp32-elf-gcc\1.22.0-80-g6c4433a-5.2.0 -verbose C:\Users\per\AppData\Local\Temp\arduino_modified_sketch_19197\sketch_dec31a.ino

the temporary build folder is C:\Users\per\AppData\Local\Temp\arduino_build_889992.

Open the .ino.cpp file in the sketch subfolder of the temporary build folder with a text editor.

The temporary build folder will be deleted when you exit the Arduino IDE.

Perhaps. Keep in mind, you have to do that anyways if you were using any IDE for "non-lazy" programmers.

Hmm and what if the sketch spans to multiple tabs ?

When you encounter odd errors like this, ....

Will do what that!

I am now getting the same issue on other sketches as well.

It seems that this "glitch" appears after some small insignificant modification ie change of variable name or adding a comment or even an empty line . However, once it happens reverting back to the original sketch prior to that modification, doesn't always stop the error from appearing!

Watcher: Hmm and what if the sketch spans to multiple tabs ?

Before generating function prototypes, the Arduino IDE concatenates all .ino files in your sketch into a single file, starting with the file that matches the sketch folder name, followed by the rest in alphabetical order. You can put the prototypes wherever you like, as long as they occur before the first time the function is referenced in the code.

More information on the sketch build process: https://github.com/arduino/Arduino/wiki/Build-Process