What causes: warning: ‘EEPROMwl’ was declared ‘extern’ and later ‘static’

Six years ago I wrote some code for an UNO. There were no errors or warnings back then. Recently, I went back to revisit the code and now there are warnings popping up. I suspect the current IDE dislikes something that the older version didn't. Since I'm am not declaring any "static" or "extern" values, can the errors be coming from a .cpp or .h file? I'm no expert so it could be obvious to someone more experienced.
Here is the code:

// #include <Mouse.h>

/*
 * K1YPP MAGNETIC LOOP ANTENNA STEPPER MOTOR SKETCH FOR ARDUINO UNO
 * 12 April, 2018
 * 
 * This sketch controls a stepper motor to drive a threaded shaft to tune a magnetic loop
 * antenna. There are some variable definitions in the beginning, followed by a setup() routine
 * that initially runs to preset things.
 * Next comes the main loop(). The program keeps looping until a band switch is depressed, which
 * calls for the motor to move the shaft to the new position. If the operator needs to
 * fine tune things, a rotary encoder is turned, either CW or CCW. An interrupt routine
 * handles the encoder movements (see below)  and, if a Arduino IDE serial port is enabled, the physical
 * count of the location of the shaft is displayed.
 * 
 * Should there be a power failure OR the power switch to the stepper motor is turned off, the 
 * power fail routine will write the current shaft position (counter) to EEPROM and
 * await shutdown. If the Arduino is still powered from the computer/USB port, the program will
 * still run but the motor won't respond. This can be used to change the counter without
 * moving the shaft, should the two need syncrhonization. When motor power is restored the 
 * Arduino will read the EEPROM and everything is good to go.
 * 
 * The read/write to EEPROM uses the EEPROMWearLevel library from github. This library spreads 
 * the writes to EEPROM over the entire 1024 addresses in the Arduino UNO. The EEPROM has a 
 * maximum guaranteed write life of 100k writes (usually it is many times that, but data errors
 * could happen after 100k writes). In the real world use of this sketch, there are not too many
 * writes to EEPROM in a given day, 100k power fails amounts to a very busy day!
 * See: https://github.com/PRosenb/EEPROMWearLevel
 * for more details.
 * 
 * The Rotary Encoder library will dump integers to the serial
 * port. The integers increment or decrement depending on the direction
 * of rotation.
 *
 * See here for an example using interrupts rather than polling.
 * From URL: http://www.buxtronix.net/2011/10/rotary-encoders-done-properly.html
 * 
 * 
 */

// Lets begin the sketch:

#include <Rotary.h>
#include <EEPROMWearLevel.h>

#define EEPROM_LAYOUT_VERSION 1
#define AMOUNT_OF_INDEXES 1
#define INDEX_RING_BUFFER 0

// Rotary encoder is wired with the common to ground and the two
// outputs to pins 2 and 3.
Rotary rotary = Rotary(2, 3);

enum PinAssignments {
  encoderPinA = 2,    // right
  encoderPinB = 3,    // left
  clearButton = 5,    // Encoder swtich
};

// Currently 15M band is 1995

// Defines 17M location variables (Currently 17M band, 18.068 Mhz)

int long TenM_Pos = 1491;   // 1491 predefined travel distance to 15M from 20M
int long TenM_sw = 11;      // 17M target select switch

// Defines 15M location variables (Currently 15M band, 21.000 Mhz)

int long FifteenM_Pos = 1995;   // 1995 predefined travel distance to 12M from 20M
int long FifteenM_sw = 10;      // 15M target select switch

// Defines xxM location variables (used for adding another bandswitch in future

// int long xxM_Pos = xxxx;   // predefined travel distance to xxM from 20M
// to determine xxxx, measure distance on shaft from 40M position to new band. 
// Multiply inches * 200 = new xxxx.
// int long xxM_sw = xx;      // xxM target select switch, replace xx with pin number on Arduino


// Defines 20M location variables

int long TwentyM_Pos = 0;   // 1995 predefined travel distance to 20M from 10M

// defines pins numbers for motor driver A4988
    const int stepPin = 8; 
    const int dirPin = 9; 

// Counter that will be incremented or decremented by rotation.
long counter = 0;
long value = counter; //largest value that might be written to EEPROM
long FortyM_start = 0;   // Starting position for 40M


// defines power failure sensing
    int DCdown = 6;
    int PowerFail;
    int unsaved = LOW;

void setup() {

// Sets power failure sense pin
  pinMode(DCdown, INPUT_PULLUP);

  // Sets the two pins as Outputs for stepper motor
  pinMode(stepPin,OUTPUT);      
  pinMode(dirPin,OUTPUT);
  
  pinMode(encoderPinA, INPUT);      
  pinMode(encoderPinB, INPUT);
  pinMode(clearButton, INPUT);

  // turn on pullup resistors
  digitalWrite(encoderPinA, HIGH);
  digitalWrite(encoderPinB, HIGH);
  digitalWrite(clearButton, HIGH);
  digitalWrite(FifteenM_sw, HIGH);
  digitalWrite(TenM_sw, HIGH);
  //   digitalWrite(xx_sw, HIGH); enabled if adding another band switch
  digitalWrite(DCdown, HIGH);

  Serial.begin(115200);
    while (!Serial);
    
  attachInterrupt(0, rotate, CHANGE);
  attachInterrupt(1, rotate, CHANGE);
  
  EEPROMwl.begin(EEPROM_LAYOUT_VERSION, AMOUNT_OF_INDEXES);

  readData(); //reads data stored in EEPROM to find last used counter value
  Serial.print("V7.0:Power up: counter: ");
  Serial.println(counter);
}

void loop() {

 PowerFail = digitalRead ( DCdown );  

  if ( PowerFail == HIGH && unsaved == LOW) {
  
  Serial.print("V7.0:Going down for power failure: counter: ");
  Serial.println(counter);

    writeData();  readData(); //    we only want to save to eeprom once when power fails

  unsaved = HIGH;  
  delay(750);
}

 if ( PowerFail == LOW ) {
    unsaved = LOW;
}


// ***********   reset/20 Meters   **********  
/*

Sets counter to "0" which is lowest freq., 40M.
Upon power up, the tuning position is assumed to be 40M. Future m        
location stored in EEPROM and that position will be recalled upon boot up.

*/

  if (digitalRead(clearButton) == LOW )  {
  Serial.println("Line 165: counter");
  Serial.println(counter);
  
  while (counter < 0) {  
    CCW_direction();  
  }

  while (counter > 0) {
    CW_direction();
  }
   writeData();
   readData();
 } 

//  ************    10 Meter switch handler:     ************

  if (digitalRead(TenM_sw) == LOW )  {
   Serial.println("Line 182: counter");
   Serial.println(counter);
  
  while (counter < TenM_Pos) {  
    CCW_direction();  
  }

  while (counter > TenM_Pos) {
    CW_direction();
  }
   writeData();
   readData();
}

//  ************    15 Meter switch handler:     ************

  if (digitalRead(FifteenM_sw) == LOW )  {
   Serial.println("Line 199: counter");
  Serial.println(counter);
  
  while (counter < FifteenM_Pos) {
      
    CCW_direction();  
  }

  while (counter > FifteenM_Pos) {
    
    CW_direction();
  }
   writeData();
   readData();
}

}

/*
 //  ************    xx Meter switch handler (template):     ************
// Either copy this section, or remove comment limiters to enable for a new band.
// Replace anything that has "xx" with the band of interest, such as "FifteenM_sw"
  if (digitalRead(xxM_sw) == LOW )  {
   Serial.println("Line 222: counter");
  Serial.println(counter);
  
  while (counter < xxM_Pos) {
      
    CCW_direction();  
  }

  while (counter > xxM_Pos) {
    
    CW_direction();
  }
   writeData();
   readData();
}

}
 * 
 * 
 */
 
void writeData() {

//  writes a new value no matter what value was written before.
  EEPROMwl.putToNext(INDEX_RING_BUFFER, counter);

}


void readData() {

  int dataLength = 4;

  long currentIndex = EEPROMwl.getCurrentIndexEEPROM(INDEX_RING_BUFFER, dataLength);

      Serial.print("257: EEPROM stored value: ");
      Serial.println(EEPROM.get(currentIndex, value));
      counter = (EEPROM.get(currentIndex, value));
      
  int EEPROM_address = (currentIndex);
      Serial.print("262: EEPROM_address:");
      Serial.println(EEPROM_address);    
 
}


void CCW_direction() {    
    
        digitalWrite(dirPin,HIGH); // Enables the motor to move in a CCW  direction (higher frequency)    
      for(int long x =   0; x < 20; x++) {
        digitalWrite(stepPin,HIGH);
        delayMicroseconds(800); 
        digitalWrite(stepPin,LOW); 
        delayMicroseconds(800);
      }
 
counter++; 
  Serial.print("Line 279 CCW: ");
      Serial.println(counter);
}

void CW_direction(){

    // Rotation requests for 20 pulse movement CW 

        digitalWrite(dirPin,LOW); // Enables the motor to move in a CW direction (lower frequency)
      // Makes 20 pulses for making 1/10 cycle rotation
      for(long int x = 0; x < 20; x++) {
        digitalWrite(stepPin,HIGH); 
        delayMicroseconds(800); 
        digitalWrite(stepPin,LOW); 
        delayMicroseconds(800); 
      }
     counter--; 
  Serial.print("Line 296 CW: ");
      Serial.println(counter);

}



// rotate is called anytime the rotary inputs change state.
void rotate() {
  unsigned char result = rotary.process();
  if (result == DIR_CCW) {
    counter++;
    Serial.println(counter);

// Rotary encoder requests 20 pulse movement CCW 


        digitalWrite(dirPin,HIGH); // Enables the motor to move in a CCW direction (raises frequency)
      // Makes 20 pulses for making 1/10 cycle rotation
      for(int x = 0; x < 20; x++) {
        digitalWrite(stepPin,HIGH); 
        delayMicroseconds(800);
        digitalWrite(stepPin,LOW); 
        delayMicroseconds(800); 
         
  }

    
  } else if (result == DIR_CW) {
    counter--;
    Serial.println(counter);

    // Rotary encoder requests 20 pulse movement CW 

        digitalWrite(dirPin,LOW); // Enables the motor to move in a CW direction (lower frequency)
      // Makes 20 pulses for making 1/10 cycle rotation
      for(long int x = 0; x < 20; x++) {
        digitalWrite(stepPin,HIGH); 
        delayMicroseconds(800); 
        digitalWrite(stepPin,LOW); 
        delayMicroseconds(800); 

      }

  
  }
}

Here are the warnings:
IDE ver. 1.8.19


/home/dennis/Arduino/libraries/EEPROMWearLevel-master/EEPROMWearLevel.cpp:4:24: warning: ‘EEPROMwl’ was declared ‘extern’ and later ‘static’ [-fpermissive]
static EEPROMWearLevel EEPROMwl;
^
In file included from /home/dennis/Arduino/libraries/EEPROMWearLevel-master/EEPROMWearLevel.cpp:2:0:
/home/dennis/Arduino/libraries/EEPROMWearLevel-master/EEPROMWearLevel.h:323:24: note: previous declaration of ‘EEPROMwl’
extern EEPROMWearLevel EEPROMwl;
^
/home/dennis/Arduino/libraries/EEPROMWearLevel-master/EEPROMWearLevel.cpp: In member function ‘void EEPROMWearLevel::begin(byte, const int*)’:
/home/dennis/Arduino/libraries/EEPROMWearLevel-master/EEPROMWearLevel.cpp:39:35: warning: ‘sizeof’ on array function parameter ‘lengths’ will return size of ‘const int*’ [-Wsizeof-array-argument]
amountOfIndexes = sizeof(lengths);
^
/home/dennis/Arduino/libraries/EEPROMWearLevel-master/EEPROMWearLevel.cpp:37:73: note: declared here
void EEPROMWearLevel::begin(const byte layoutVersion, const int lengths[]) {
^
/home/dennis/Arduino/libraries/EEPROMWearLevel-master/EEPROMWearLevel.cpp:44:41: warning: ‘sizeof’ on array function parameter ‘lengths’ will return size of ‘const int*’ [-Wsizeof-array-argument]
for (index = 0; index < sizeof(lengths); index++) {
^
/home/dennis/Arduino/libraries/EEPROMWearLevel-master/EEPROMWearLevel.cpp:37:73: note: declared here
void EEPROMWearLevel::begin(const byte layoutVersion, const int lengths[]) {
^
Sketch uses 6082 bytes (18%) of program storage space. Maximum is 32256 bytes.
Global variables use 449 bytes (21%) of dynamic memory, leaving 1599 bytes for local variables. Maximum is 2048 bytes.


Hopefully I posted this correctly, it has been a VERY long time since I've worked on this stuff.

Dennis

Your program compiled for me with an Uno R3 selected.

I used the current EEPROMWearLevel library, which has no static declaration on line 4 of EEPROMWearLevel.cpp.

But the 9 year version of the library does.

I'm going to go with there's been an update to the library 4 years ago that your setup hasn't picked up, and a compiler update somewhere along the way is now annoyed by the static declaration in the library.

Try updating your library.

1 Like

I'll see if I can figure it out and get back to you van_der_decken. Thanks.

You are correct van_der_decken, I must have had the incorrect library file, the error is now gone. Thanks.
Now I have a rotary.h error, so I will go and post that problem in the appropriate forum.
Dennis

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.