Compile error for mega or mega 2560

Hello,
I am testing out a 7-segment display I am intentionally trying to make from scratch (using arduino mega) as a fun exercise.

I have a counting function in my void loop so supposedly my triple digit 7-segment display should just count from 1-100 and display each number appropriately. Below is my code, but below that is my compile error message. I am not sure what is causing it. Other codes compile just fine but this one is spitting this error back. Will check out the "how to submit a full bug report" link but hoping someone here has the knowledge to help me resolve this too! Thanks!

//7 seg test

/*
    The LED strips circuit:
      
           C
          ____
         |    |
      E  |____|  A
         | G  |
      F  |____|  B 
                
           D

*/


// Define a structure to contain all the related data for executing a note
typedef struct 
{
  const int pin;              // output pin
  const int numerals[];  // digit values with output pins
} numbers_and_SEGs;

numbers_and_SEGs ONES[] =  ///ones place
{
  {2, {0, 1, 2, 3, 4, 7, 8, 9, 9}}, //A
  {3, {0, 1, 3, 4, 5, 6, 7, 8, 9}}, //B
  {4, {0, 2, 3, 5, 6, 7, 8, 9, 9}}, //C
  {5, {0, 2, 3, 5, 6, 8, 9, 9, 9}}, //D
  {6, {0, 4, 5, 6, 8, 9, 9, 9, 9}}, //E
  {7, {0, 2, 6, 8, 8, 8, 8, 8, 8}},  //F
  {8, {2, 3, 4, 6, 8, 9, 9, 9, 9}}, //G
};

numbers_and_SEGs TENS[] =  ///tens place
{
  {22, {0, 1, 2, 3, 4, 7, 8, 9, 9}}, //A
  {23, {0, 1, 3, 4, 5, 6, 7, 8, 9}}, //B
  {24, {0, 2, 3, 5, 6, 7, 8, 9, 9}}, //C
  {25, {0, 2, 3, 5, 6, 8, 9, 9, 9}}, //D
  {26, {0, 4, 5, 6, 8, 9, 9, 9, 9}}, //E
  {27, {0, 2, 6, 8, 8, 8, 8, 8, 8}},  //F
  {28, {2, 3, 4, 6, 8, 9, 9, 9, 9}}, //G
};

int DECIMAL = 29;
int HUNDREDS = 30;



void SHOW(int val) ///ACTUALLY CONTROLS THE DISPLAY!!!!!
{

  if (val == 0) //in the event of a reset all scores will be zero 
  {
    for (int i = 0; i < 7; i++)
      {
      digitalWrite(ONES[i].pin, LOW);
      }   
    for (int j = 0; j < 7; j++)
      {
      digitalWrite(TENS[j].pin, LOW);
      }
    digitalWrite(HUNDREDS, LOW);
    digitalWrite(DECIMAL, LOW);
  }
  
  int ones = (val%10);  /// % moduloooo!! divides, then remainder is what is returned
  int tens = ((val/10)%10);
  int hundreds = ((val/100)%10);
  
  //for each digit, see if it is inside the array above and send HIGH for each respective pins 
  for (int n = 0; n < 7; n++) //ONES PLACE BEHAVIOR
  { 
    for (int m = 0; m < 9; m++)
    {
      if (ones == ONES[n].numerals[m])
      {
        digitalWrite(ONES[n].pin, HIGH);
        digitalWrite(DECIMAL, HIGH);
      }
    }
  }
  
  for (int o = 0; o < 7; o++) //TENS PLACE BEHAVIOR
  { 
    for (int p = 0; p < 9; p++)
    {
      if (tens == TENS[o].numerals[p])
      {
        digitalWrite(TENS[o].pin, HIGH);
        digitalWrite(DECIMAL, HIGH);
      }
    }
  }
  
  if (hundreds == 1) //HUNDREDS PLACE BEHAVIOR
  {
    digitalWrite(HUNDREDS, HIGH);
    digitalWrite(DECIMAL, HIGH);
  }
  if (hundreds == 0)
  {
    digitalWrite(HUNDREDS, LOW);
  }
  
}



void setup() {
  // put your setup code here, to run once:
  for (int q = 0; q < 7; q++)
  {
    pinMode(ONES[q].pin,OUTPUT);
    digitalWrite(ONES[q].pin, LOW);
  }
  
  for (int r = 0; r < 7; r++)
  {
    pinMode(TENS[r].pin,OUTPUT);
    digitalWrite(TENS[r].pin, LOW);
  }

  pinMode(HUNDREDS, OUTPUT);
  digitalWrite(HUNDREDS, LOW);

  pinMode(DECIMAL, OUTPUT);
  digitalWrite(DECIMAL, LOW);

}

void loop() {
  // put your main code here, to run repeatedly:
  for (int k = 0; k<=100; k++)
  {
    SHOW(k);
    Serial.println(k);
    delay(500);
    SHOW(0);
    delay(500);
  }
}
Arduino: 1.8.20 Hourly Build 2021/12/20 07:34 (Mac OS X), Board: "Arduino Mega or Mega 2560, ATmega2560 (Mega 2560)"











/Applications/Arduino.app/Contents/Java/arduino-builder -dump-prefs -logger=machine -hardware /Applications/Arduino.app/Contents/Java/hardware -tools /Applications/Arduino.app/Contents/Java/tools-builder -tools /Applications/Arduino.app/Contents/Java/hardware/tools/avr -built-in-libraries /Applications/Arduino.app/Contents/Java/libraries -libraries /Users/eijifrey/Documents/Arduino/libraries -fqbn=arduino:avr:mega:cpu=atmega2560 -ide-version=10820 -build-path /var/folders/f5/wmykvlzd0ml0hh17g7wscpvm0000gn/T/arduino_build_545089 -warnings=none -build-cache /var/folders/f5/wmykvlzd0ml0hh17g7wscpvm0000gn/T/arduino_cache_885951 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.avr-gcc.path=/Applications/Arduino.app/Contents/Java/hardware/tools/avr -prefs=runtime.tools.avr-gcc-7.3.0-atmel3.6.1-arduino7.path=/Applications/Arduino.app/Contents/Java/hardware/tools/avr -prefs=runtime.tools.avrdude.path=/Applications/Arduino.app/Contents/Java/hardware/tools/avr -prefs=runtime.tools.avrdude-6.3.0-arduino17.path=/Applications/Arduino.app/Contents/Java/hardware/tools/avr -prefs=runtime.tools.arduinoOTA.path=/Applications/Arduino.app/Contents/Java/hardware/tools/avr -prefs=runtime.tools.arduinoOTA-1.3.0.path=/Applications/Arduino.app/Contents/Java/hardware/tools/avr -verbose /Users/eijifrey/Documents/CAREER/EMPLOYERS/PINK SPARROW/2022/Price is Right (CBS)/7_segment_test/7_segment_test.ino
/Applications/Arduino.app/Contents/Java/arduino-builder -compile -logger=machine -hardware /Applications/Arduino.app/Contents/Java/hardware -tools /Applications/Arduino.app/Contents/Java/tools-builder -tools /Applications/Arduino.app/Contents/Java/hardware/tools/avr -built-in-libraries /Applications/Arduino.app/Contents/Java/libraries -libraries /Users/eijifrey/Documents/Arduino/libraries -fqbn=arduino:avr:mega:cpu=atmega2560 -ide-version=10820 -build-path /var/folders/f5/wmykvlzd0ml0hh17g7wscpvm0000gn/T/arduino_build_545089 -warnings=none -build-cache /var/folders/f5/wmykvlzd0ml0hh17g7wscpvm0000gn/T/arduino_cache_885951 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.avr-gcc.path=/Applications/Arduino.app/Contents/Java/hardware/tools/avr -prefs=runtime.tools.avr-gcc-7.3.0-atmel3.6.1-arduino7.path=/Applications/Arduino.app/Contents/Java/hardware/tools/avr -prefs=runtime.tools.avrdude.path=/Applications/Arduino.app/Contents/Java/hardware/tools/avr -prefs=runtime.tools.avrdude-6.3.0-arduino17.path=/Applications/Arduino.app/Contents/Java/hardware/tools/avr -prefs=runtime.tools.arduinoOTA.path=/Applications/Arduino.app/Contents/Java/hardware/tools/avr -prefs=runtime.tools.arduinoOTA-1.3.0.path=/Applications/Arduino.app/Contents/Java/hardware/tools/avr -verbose /Users/eijifrey/Documents/CAREER/EMPLOYERS/PINK SPARROW/2022/Price is Right (CBS)/7_segment_test/7_segment_test.ino
Using board 'mega' from platform in folder: /Applications/Arduino.app/Contents/Java/hardware/arduino/avr
Using core 'arduino' from platform in folder: /Applications/Arduino.app/Contents/Java/hardware/arduino/avr
Detecting libraries used...
/Applications/Arduino.app/Contents/Java/hardware/tools/avr/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=10820 -DARDUINO_AVR_MEGA2560 -DARDUINO_ARCH_AVR -I/Applications/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino -I/Applications/Arduino.app/Contents/Java/hardware/arduino/avr/variants/mega /var/folders/f5/wmykvlzd0ml0hh17g7wscpvm0000gn/T/arduino_build_545089/sketch/7_segment_test.ino.cpp -o /dev/null
Generating function prototypes...
/Applications/Arduino.app/Contents/Java/hardware/tools/avr/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=10820 -DARDUINO_AVR_MEGA2560 -DARDUINO_ARCH_AVR -I/Applications/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino -I/Applications/Arduino.app/Contents/Java/hardware/arduino/avr/variants/mega /var/folders/f5/wmykvlzd0ml0hh17g7wscpvm0000gn/T/arduino_build_545089/sketch/7_segment_test.ino.cpp -o /var/folders/f5/wmykvlzd0ml0hh17g7wscpvm0000gn/T/arduino_build_545089/preproc/ctags_target_for_gcc_minus_e.cpp
/Applications/Arduino.app/Contents/Java/tools-builder/ctags/5.8-arduino11/ctags -u --language-force=c++ -f - --c++-kinds=svpf --fields=KSTtzns --line-directives /var/folders/f5/wmykvlzd0ml0hh17g7wscpvm0000gn/T/arduino_build_545089/preproc/ctags_target_for_gcc_minus_e.cpp
Compiling sketch...
/Applications/Arduino.app/Contents/Java/hardware/tools/avr/bin/avr-g++ -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -MMD -flto -mmcu=atmega2560 -DF_CPU=16000000L -DARDUINO=10820 -DARDUINO_AVR_MEGA2560 -DARDUINO_ARCH_AVR -I/Applications/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino -I/Applications/Arduino.app/Contents/Java/hardware/arduino/avr/variants/mega /var/folders/f5/wmykvlzd0ml0hh17g7wscpvm0000gn/T/arduino_build_545089/sketch/7_segment_test.ino.cpp -o /var/folders/f5/wmykvlzd0ml0hh17g7wscpvm0000gn/T/arduino_build_545089/sketch/7_segment_test.ino.cpp.o
Compiling libraries...
Compiling core...
Using precompiled core: /var/folders/f5/wmykvlzd0ml0hh17g7wscpvm0000gn/T/arduino_cache_885951/core/core_arduino_avr_mega_cpu_atmega2560_51f02b7210b938436b779d1c032618e1.a
Linking everything together...
/Applications/Arduino.app/Contents/Java/hardware/tools/avr/bin/avr-gcc -w -Os -g -flto -fuse-linker-plugin -Wl,--gc-sections -mmcu=atmega2560 -o /var/folders/f5/wmykvlzd0ml0hh17g7wscpvm0000gn/T/arduino_build_545089/7_segment_test.ino.elf /var/folders/f5/wmykvlzd0ml0hh17g7wscpvm0000gn/T/arduino_build_545089/sketch/7_segment_test.ino.cpp.o /var/folders/f5/wmykvlzd0ml0hh17g7wscpvm0000gn/T/arduino_build_545089/../arduino_cache_885951/core/core_arduino_avr_mega_cpu_atmega2560_51f02b7210b938436b779d1c032618e1.a -L/var/folders/f5/wmykvlzd0ml0hh17g7wscpvm0000gn/T/arduino_build_545089 -lm
lto1: internal compiler error: in output_constructor_regular_field, at varasm.c:5031
libbacktrace could not find executable to open
Please submit a full bug report,
with preprocessed source if appropriate.
See <https://gcc.gnu.org/bugs/> for instructions.
lto-wrapper: fatal error: /Applications/Arduino.app/Contents/Java/hardware/tools/avr/bin/avr-gcc returned 1 exit status
compilation terminated.
/Applications/Arduino.app/Contents/Java/hardware/tools/avr/bin/../lib/gcc/avr/7.3.0/../../../../avr/bin/ld: error: lto-wrapper failed
collect2: error: ld returned 1 exit status
exit status 1
Error compiling for board Arduino Mega or Mega 2560.


I am sure if you remake this strange construct for simply lighting the segment you eliminate the error too

@kolaha Can you explain this further? Or provide an example?

Hello eijifrey
Check the size of the array numerals[]:

typedef struct 
{
  const int pin;              // output pin
  const int numerals[9];  // digit values with output pins
} numbers_and_SEGs;

Have a nice day and enjoy coding in C++.

2 Likes

???? Is there strips or 7 segment digits displays?

LED strips make up each segment

I am using an arduino Mega though...also, any insight in to how to resolve my compile error?

Just read this part

/var/folders/f5/wmykvlzd0ml0hh17g7wscpvm0000gn/T/arduino_build_545089/../arduino_cache_885951/core/core_arduino_avr_mega_cpu_atmega2560_51f02b7210b938436b779d1c032618e1.a -L/var/folders/f5/wmykvlzd0ml0hh17g7wscpvm0000gn/T/arduino_build_545089 -lm
lto1: internal compiler error: in output_constructor_regular_field, at varasm.c:5031
libbacktrace could not find executable to open
Please submit a full bug report,
with preprocessed source if appropriate.
See <https://gcc.gnu.org/bugs/> for instructions.

It says " internal compiler error: in output_constructor_regular_field, at varasm.c:5031"

I recon you cannot do anything else than

  • report this issue as mentioned in the debug messages
    and/or
  • reinstall the IDE and cross fingers ...

Hello everyone, this problem has been solved reply #4.

1 Like

The error is in setup()

Rework this commented code


/*
  for (int q = 0; q < 7; q++)
  {
    pinMode(ONES[q].pin,OUTPUT);
    digitalWrite(ONES[q].pin, LOW);
  }

  for (int r = 0; r < 7; r++)
  {
    pinMode(TENS[r].pin,OUTPUT);
    digitalWrite(TENS[r].pin, LOW);
  }
*/
1 Like

Hey thanks guys! I must be a bit behind here...everyone keeps pointing to that part in my setup but can someone explain why? Or how to change it?

Not necessarily in setup. Try specifying the array size in the struct.
< edit > as pointed out in reply #4

// Define a structure to contain all the related data for executing a note
typedef struct
{
  const int pin;              // output pin
  const int numerals[9];  // digit values with output pins
} numbers_and_SEGs;
1 Like

The following sketch will exhibit the error:

// Define a structure to contain all the related data for executing a note
typedef struct
{
  const int pin;              // output pin
  const int numerals[];  // digit values with output pins
} numbers_and_SEGs;

numbers_and_SEGs ONES[] =  ///ones place
{
  {2, {0, 1, 2, 3, 4, 7, 8, 9, 9}}, //A
  {3, {0, 1, 3, 4, 5, 6, 7, 8, 9}}, //B
  {4, {0, 2, 3, 5, 6, 7, 8, 9, 9}}, //C
  {5, {0, 2, 3, 5, 6, 8, 9, 9, 9}}, //D
  {6, {0, 4, 5, 6, 8, 9, 9, 9, 9}}, //E
  {7, {0, 2, 6, 8, 8, 8, 8, 8, 8}},  //F
  {8, {2, 3, 4, 6, 8, 9, 9, 9, 9}}, //G
};

void setup() {
    pinMode(ONES[random(7)].pin, OUTPUT);
}

void loop() {
}

Specifying that numerals is an array of 9 elements eliminates the error message. Apparently the linker has problems with a variable size array in a struct.

1 Like

Just declaring the array and never using it still exhibits the error:

// Define a structure to contain all the related data for executing a note
typedef struct
{
  const int pin;              // output pin
  const int numerals[];  // digit values with output pins
} numbers_and_SEGs;

volatile const numbers_and_SEGs ONES[] =  ///ones place
{
  {2, {0, 1, 2, 3, 4, 7, 8, 9, 9}}, //A
  {3, {0, 1, 3, 4, 5, 6, 7, 8, 9}}, //B
  {4, {0, 2, 3, 5, 6, 7, 8, 9, 9}}, //C
  {5, {0, 2, 3, 5, 6, 8, 9, 9, 9}}, //D
  {6, {0, 4, 5, 6, 8, 9, 9, 9, 9}}, //E
  {7, {0, 2, 6, 8, 8, 8, 8, 8, 8}},  //F
  {8, {2, 3, 4, 6, 8, 9, 9, 9, 9}}, //G
};

void setup() {
}

void loop() {
}
lto1: internal compiler error: in output_constructor_regular_field, at varasm.c:5031
Please submit a full bug report,
with preprocessed source if appropriate.
See <https://gcc.gnu.org/bugs/> for instructions.
lto-wrapper: fatal error: /home/test/.arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7/bin/avr-gcc returned 1 exit status
compilation terminated.
/home/test/.arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7/bin/../lib/gcc/avr/7.3.0/../../../../avr/bin/ld: error: lto-wrapper failed
collect2: error: ld returned 1 exit status
exit status 1 
Error compiling for board Arduino Mega or Mega 2560.
1 Like

This compiles for me:

//7 seg test

/*
    The LED strips circuit:
      
           C
          ____
         |    |
      E  |____|  A
         | G  |
      F  |____|  B 
                
           D

*/


// Define a structure to contain all the related data for executing a note
typedef struct 
{
  const int pin;              // output pin
  const int numerals[];  // digit values with output pins
} numbers_and_SEGs;

numbers_and_SEGs ONES[] =  ///ones place
{
  {2, {0, 1, 2, 3, 4, 7, 8, 9, 9}}, //A
  {3, {0, 1, 3, 4, 5, 6, 7, 8, 9}}, //B
  {4, {0, 2, 3, 5, 6, 7, 8, 9, 9}}, //C
  {5, {0, 2, 3, 5, 6, 8, 9, 9, 9}}, //D
  {6, {0, 4, 5, 6, 8, 9, 9, 9, 9}}, //E
  {7, {0, 2, 6, 8, 8, 8, 8, 8, 8}},  //F
  {8, {2, 3, 4, 6, 8, 9, 9, 9, 9}}, //G
};

numbers_and_SEGs TENS[] =  ///tens place
{
  {22, {0, 1, 2, 3, 4, 7, 8, 9, 9}}, //A
  {23, {0, 1, 3, 4, 5, 6, 7, 8, 9}}, //B
  {24, {0, 2, 3, 5, 6, 7, 8, 9, 9}}, //C
  {25, {0, 2, 3, 5, 6, 8, 9, 9, 9}}, //D
  {26, {0, 4, 5, 6, 8, 9, 9, 9, 9}}, //E
  {27, {0, 2, 6, 8, 8, 8, 8, 8, 8}},  //F
  {28, {2, 3, 4, 6, 8, 9, 9, 9, 9}}, //G
};

int DECIMAL = 29;
int HUNDREDS = 30;



void SHOW(int val) ///ACTUALLY CONTROLS THE DISPLAY!!!!!
{

  if (val == 0) //in the event of a reset all scores will be zero 
  {
    for (int i = 0; i < 7; i++)
      {
      digitalWrite(ONES[i].pin, LOW);
      }   
    for (int j = 0; j < 7; j++)
      {
      digitalWrite(TENS[j].pin, LOW);
      }
    digitalWrite(HUNDREDS, LOW);
    digitalWrite(DECIMAL, LOW);
  }
  
  int ones = (val%10);  /// % moduloooo!! divides, then remainder is what is returned
  int tens = ((val/10)%10);
  int hundreds = ((val/100)%10);
  
  //for each digit, see if it is inside the array above and send HIGH for each respective pins 
  for (int n = 0; n < 7; n++) //ONES PLACE BEHAVIOR
  { 
    for (int m = 0; m < 9; m++)
    {
      if (ones == ONES[n].numerals[m])
      {
        digitalWrite(ONES[n].pin, HIGH);
        digitalWrite(DECIMAL, HIGH);
      }
    }
  }
  
  for (int o = 0; o < 7; o++) //TENS PLACE BEHAVIOR
  { 
    for (int p = 0; p < 9; p++)
    {
      if (tens == TENS[o].numerals[p])
      {
        digitalWrite(TENS[o].pin, HIGH);
        digitalWrite(DECIMAL, HIGH);
      }
    }
  }
  
  if (hundreds == 1) //HUNDREDS PLACE BEHAVIOR
  {
    digitalWrite(HUNDREDS, HIGH);
    digitalWrite(DECIMAL, HIGH);
  }
  if (hundreds == 0)
  {
    digitalWrite(HUNDREDS, LOW);
  }
  
}



void setup() {
/*
  // put your setup code here, to run once:
  for (int q = 0; q < 7; q++)
  {
    pinMode(ONES[q].pin,OUTPUT);
    digitalWrite(ONES[q].pin, LOW);
  }
*/
/*
  for (int r = 0; r < 7; r++)
  {
    pinMode(TENS[r].pin,OUTPUT);
    digitalWrite(TENS[r].pin, LOW);
  }
*/
  pinMode(HUNDREDS, OUTPUT);
  digitalWrite(HUNDREDS, LOW);

  pinMode(DECIMAL, OUTPUT);
  digitalWrite(DECIMAL, LOW);

}

void loop() {
/*
  for (int k = 0; k<=100; k++)
  {
    SHOW(k);
    Serial.println(k);
    delay(500);
    SHOW(0);
    delay(500);
  }
*/
}


Sketch uses 1366 bytes (0%) of program storage space. Maximum is 253952 bytes.
Global variables use 9 bytes (0%) of dynamic memory, leaving 8183 bytes for local variables. Maximum is 8192 bytes.

The arrays are never used in your code, so are never created by the compiler, therefore the linker never sees the problem. Notice in reply #17 I declared the array as volatile to force its creation, and in reply #16 the compiler is forced to create the array because I use a random element of the array, specifying a fixed element would compile properly because the compiler substitutes the number from the array and never creates the array itself.

1 Like

Ah, ha... head hung in shame ...
Too many responses for today, too many windows open, too hard to follow-up on ... well, I screwed-up but I nailed the V-USB enumeration!

Leaving the "numerals" with unspecified length seems to be causing the problem. Change it to specify the maximum needed and it will compile without error:
const int numerals[9]; // digit values with output pins

1 Like

Yup specifying the size was the solution! Big thanks to everyone involved here!

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