Function reported as undefined but it is present

Refactoring a sketch i found that this code generate the error: "Batt_Tester_v1_0_3x:27: error: 'LeggiDefaults' was not declared in this scope".

the error disappeared commenting the line setting the LCD parameters but:

  1. the code for LCD display should not be compiled because LCDScreen if undefined;
  2. commenting the LCD settings doesn't interfere with the language sintax of the sketch.

Is this a bug??
am I wrong in something?

Thank you
Bye
Fabrizio

//#define LCDScreen

#include <FastIO.h> 

#ifdef LCDScreen

#include <I2CIO.h>
#include <LCD.h>
#include <LiquidCrystal.h>
#include <LiquidCrystal_I2C.h>
#include <LiquidCrystal_SR.h>
#include <LiquidCrystal_SR2W.h>
#include <LiquidCrystal_SR3W.h>
#include <Wire.h>

LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);  // Set the LCD I2C address

#endif // LCDScreen
//---------------------------------------------------------------------------

// the setup function runs once when you press reset or power the board
void setup() {   
  LeggiDefaults();
  }
//---------------------------------------------------------------------------

// the loop function runs over and over again forever
void loop()
{
}
//---------------------------------------------------------------------------

void LeggiDefaults()
{
}
//---------------------------------------------------------------------------

Is this a bug??
am I wrong in something?

No and yes.

Enable verbose mode when compiling, using File + Preferences.

Look for the cpp file that is created from the ino file, in the build directory. Look at where the IDE made its modifications to your ino file, to understand why it won't compile.

If you just MUST use conditional compilation, add

byte me;

as the first line in the ino file, to give the IDE a clue where to make its changes.

i have seen.
the IDE has problem working in this scenario.

I hope this will be solved in next releases of it. All other c++ ide and compiler i use accept this code.

Thanks for the workaround.

Fabrizio

ik6gtf:
I hope this will be solved in next releases of it.

I doubt it. What some call a bug others call a feature. Without that, we'd have to teach the newbies about function prototypes. Someone thought that was a lesson better left for another day.