Compiler(1.8.9) can't find my function when called

Originally, I wrote the sketch in 1.6.5, which it will compile and upload with absolutely no errors or warnings- Happy Compiler :slight_smile: . However, when i try to compile the same skecth using the new IDE 1.8.9, I get a bunch of errors- Unhappy compiler :frowning: . Did something change with the formatting of sketches? My sketch is broken up into 7 tabs and a header to keep things as easy to find as possible. My main tab looks like this:

#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include "BP_Variables.h"
//Define a Bunch of things

void setup() {

Serial.begin(9600);
//Initialize all the I/O
} 

  
void loop() {
  if (DisplayPresent == 1)
  {
    checkButton();
    HMI_Encoder();
    checkMenuMode();
  }
  Lights();
  StartStop();
  TH_Encoder();
  RunMachineProgram();


}

All the functions are located in other tabs or further down in the main tab. These are the error messages I get when I try to compile in 1.8.9:

C:\Users\skennedy\Documents\Arduino\BPduino\BPduino_RS\BPduino_RS_v1_2\BPduino_RS_v1_2.ino: In function 'void loop()':

BPduino_RS_v1_2:246:5: error: 'HMI_Encoder' was not declared in this scope

     HMI_Encoder();

     ^~~~~~~~~~~

BPduino_RS_v1_2:247:5: error: 'checkMenuMode' was not declared in this scope

     checkMenuMode();

     ^~~~~~~~~~~~~

BPduino_RS_v1_2:249:3: error: 'Lights' was not declared in this scope

   Lights();

   ^~~~~~

C:\Users\skennedy\Documents\Arduino\BPduino\BPduino_RS\BPduino_RS_v1_2\BPduino_RS_v1_2.ino:249:3: note: suggested alternative: 'gets'

   Lights();

   ^~~~~~

   gets

BPduino_RS_v1_2:252:3: error: 'StartStop' was not declared in this scope

   StartStop();

   ^~~~~~~~~

C:\Users\skennedy\Documents\Arduino\BPduino\BPduino_RS\BPduino_RS_v1_2\BPduino_RS_v1_2.ino:252:3: note: suggested alternative: 'startSleep'

   StartStop();

   ^~~~~~~~~

   startSleep

BPduino_RS_v1_2:253:3: error: 'TH_Encoder' was not declared in this scope

   TH_Encoder();

   ^~~~~~~~~~

C:\Users\skennedy\Documents\Arduino\BPduino\BPduino_RS\BPduino_RS_v1_2\BPduino_RS_v1_2.ino:253:3: note: suggested alternative: 'TH_Enable'

   TH_Encoder();

   ^~~~~~~~~~

   TH_Enable

BPduino_RS_v1_2:254:3: error: 'RunMachineProgram' was not declared in this scope

   RunMachineProgram();

   ^~~~~~~~~~~~~~~~~

C:\Users\skennedy\Documents\Arduino\BPduino\BPduino_RS\BPduino_RS_v1_2\BPduino_RS_v1_2.ino: At global scope:

BPduino_RS_v1_2:281:3: error: expected unqualified-id before 'switch'

   switch (MachineSetup) {

   ^~~~~~

BPduino_RS_v1_2:304:1: error: expected declaration before '}' token

 }

 ^

exit status 1
'HMI_Encoder' was not declared in this scope

. It appears that the compiler cant find the functions I call in the main loop. However, if I cut and paste the function in above void loop() then no problem; Happy compiler :slight_smile: . There is also a random “gets” in there after the Lights() error, “startSleep”, and an “exit status 1” messages that I am not familiar with. Can someone please explain what these mean? Due to the shear size of the program (among the reasons), I have not posted the bulk of the sketch.

My sketch is broken up into 7 tabs and a header to keep things as easy to find as possible. My main tab looks like this:

Tabs?

Typically I put the function prototype before setup() and the function definition in the same file (below the main loop). The actual function (definition) shouldn't be inside a loop.

You can also make your own header & cpp files but I've never done that (with the Arduino).

Correct, so the definition happens later- outside of loop, with the function prototype occurring before setup()? But in previous IDE version I have never had to use a function prototype. I guess that's my questionable coding skills... I'll give that a try...

The Arduino IDE is supposed to auto-generate the function prototypes, but it doesn't always do a perfect job :-/

It is impossible for us to provide any specific explanation of the problem without being able to see your code. The code snippet you posted is not useful for this purpose.

I can guess that something in your code is causing the Arduino IDE's automatic function prototype generation to fail, but I can't verify or see why it failed without having your full code.

seanz2003: There is also a random "gets" in there after the Lights() error

The compiler is trying to be helpful by suggesting you meant to write "gets() instead of "Lights()". Clearly, that suggestion is not helpful in this case. I don't know why it considers those two things to be similar enough to be worth mentioning.

seanz2003: and an "exit status 1"

That just means something went wrong during the compilation. It's not really useful because there are a near infinite number of things that could cause an exit status 1. The specific error messages you saw further up in the console contain the truly helpful information.

DVDdoug: Tabs?

When a sketch contains multiple files, the Arduino IDE displays each as a separate tab. The IDE has a downward pointing triangle button on the top right of the editor window that allows to create/delete/rename tabs. If you don't specify a file extension when you create a tab, the IDE automatically makes it a .ino file.

All the .ino files of the sketch are concatenated together before being compiled so there is no functional difference between a bunch of .ino files and the same code all lumped into a single .ino file. Splitting your code into multiple files can make navigating the code much faster with a large sketch than scrolling forever through a single file.

You can also specify a .h, .cpp, .c, or .S file extension when you create a tab and those files will not undergo any sketch preprocessing. They will just be compiled as-is. .cpp is compiled as C++, .c as C, and .S as assembly.

I appreciate your comments, even if they are just general statements. Where would i go to find out more information on how the IDE's automatic function prototype generation works? Yea, adding the function prototypes sort of solves the problem. However each time i add one, the same error pops up for another function. It would appear that I have to add one for every function. its like the compiler just gives up after a few messages. The question remains... Why?

seanz2003: Where would i go to find out more information on how the IDE's automatic function prototype generation works?

There's a little information here: https://github.com/arduino/Arduino/wiki/Build-Process#pre-processing

  • Prototypes are generated for all function definitions in .ino files that don't already have prototypes. In some rare cases prototype generation may fail for some functions. To work around this, you can provide your own prototypes for these functions.
  • #line directives are added to make warning or error messages reflect the original sketch layout.

After that, there is the documentation and source code for the arduino-builder tool that does the prototype generation: https://github.com/arduino/arduino-builder

To understand the function prototype generation system and to troubleshoot when it goes wrong, it can be very helpful to examine the post-sketch preprocessing output:

  • 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.

seanz2003: The question remains... Why?

The answer remains... Post your code and I'll tell you.

The answer remains… Post your code and I’ll tell you.

Posted. please, do tell

After adding the prototypes before setup()…

void checkButton();
void HMI_Encoder();
void checkMenuMode();
void Lights();
void StartStop();
void TH_Encoder();
void RunMachineProgram();

…it still cries about the switch statement:

BPduino_RS_v1_4a:209:3: error: expected unqualified-id before 'switch'

   switch (MachineSetup) {

   ^~~~~~

BPduino_RS_v1_4a:217:1: error: expected declaration before '}' token

 }

What am i looking for exactly in the text editor?

BPduino_RS_v1_4a.zip (4.38 KB)

Not many people prefer to download and open an unknown .zip file posted by an unknown person. Post your complete code, in-line, with code tags.

. Post your complete code, in-line, with code tags.

It is multiple files. I understand your hesitancy to open a zip, but it's much easier to zip it and send one file. Instead of uploading them individually and hoping the user assembles it correctly. Also in this case, I think structure is crucial. Sure, I can combine the tabs into one and make it work, but that's not what I'm after. I want to know what breaks the automatic function prototype generator in the IDE and how to avoid it. However, all the 'light' reading I have done would suggest not using tabs or, if you do, assign a file extension to each one,but I have yet to wade through all the documentation and source code...

remove all \ from your source code \ at the end of the line in source code escapes the line ending and the next line is then a comment too

remove all \ from your source code

yep that fixed it! learn something new everyday...