Serial.println crashes compiler

I have recently seen compile errors when including a simple Serial.println command in the code.

The compiler returns;

Print.cpp:75:1: internal compiler error: Segmentation fault.

I've got some programs that seem to run fine with Serial.println in but one that doesn't.

In the failing one I am using 2 serial ports Serial and Serial1 (MEGA). Both are defined by Serial.begin (9600) and Serial1.begin(9600).

I want to see info on the serial monitor as well as be able to use a Bluetooth module on Serial1.

Is this possible?

Yes. Your problem lies in the code.

When you encounter an error you'll see a button on the right side of the orange bar "Copy error messages". Click that button. Paste the error in a message here using code tags (</> button on the forum toolbar).

ChrisTenone:
Yes. Your problem lies in the code.

It more than likely doesn't :wink: It's a bug in the toolchain (board manager v1.6.23).

We need to know the IDE version and the version of the board manager that kpg is using to confirm if this applies and how to solve.

I agree that it's likely the avr-gcc bug. There are two different Segmentation Fault errors, one of which does have a workaround you can make in your code. The other one has no known code workaround, you just need to not use avr-gcc 5.4.0-atmel3.6.1-arduino2 (Arduino AVR Boards 1.6.22-1.6.23).

The bug says...

Arduino: 1.8.7 (Windows Store 1.8.15.0) (Windows 10), Board: "Arduino/Genuino Mega or Mega 2560, ATmega2560 (Mega 2560)"

C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.15.0_x86__mdqgnx93n4wtt\hardware\arduino\avr\cores\arduino\Print.cpp: In function 'print.constprop':

C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.15.0_x86__mdqgnx93n4wtt\hardware\arduino\avr\cores\arduino\Print.cpp:75:1: internal compiler error: Segmentation fault

 }

 ^

Please submit a full bug report,

with preprocessed source if appropriate.

See <http://gcc.gnu.org/bugs.html> for instructions.

lto-wrapper.exe: fatal error: C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.15.0_x86__mdqgnx93n4wtt\hardware\tools\avr/bin/avr-gcc returned 1 exit status

compilation terminated.

c:/program files/windowsapps/arduinollc.arduinoide_1.8.15.0_x86__mdqgnx93n4wtt/hardware/tools/avr/bin/../lib/gcc/avr/5.4.0/../../../../avr/bin/ld.exe: error: lto-wrapper failed

collect2.exe: error: ld returned 1 exit status

exit status 1
Error compiling for board Arduino/Genuino Mega or Mega 2560.

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

I'm a bit new to this so not sure what to do next??

Here's how to fix it:

  • Tools > Board > Boards Manager
  • Wait for downloads to finish.
  • When you move the mouse pointer over "Arduino AVR Boards", you will see a "Select version" dropdown menu appear. Select "1.6.21".
  • Click "Install".
  • Wait for installation to finish.
  • Click "Close".

Due to a bug, this workaround doesn't work with Arduino IDE 1.8.6, but it will work with any other version of the Arduino IDE.

If you have File > Preferences > Check for updates on startup checked, the Arduino IDE may occasionally notify you that a new version of Arduino AVR Boards is available, you'll need to refrain from updating back to the new Arduino AVR Boards version, otherwise you'll be back to seeing the segmentation fault error again.

Sorry but I don't see a 'Boards Manager' pulldown in Tools.

I get options for;

Board type - MEGA 2560
Programmer type - AVRISP MKII
Processor type - AT MEGA 2560

My IDE is version 1.8.7

You didn't read what I wrote carefully enough. Maybe this will make it more clear:

  • Click on the "Tools" menu.
  • Select "Board" from the "Tools" menu.
  • Select "Boards Manager..." from the "Tools > Board" menu.

Sorry obviously needed more coffee!

All done and thanks again!!

You're welcome. I'm glad if I was able to be of assistance. Enjoy!
Per