error compiling for board arduino/genuino Uno because of specific commands

Hi, I get this message like randomly all of a sudden, everything worked well with the same code before.
heres the code:

 #define trigPin1 9
#define echoPin1 8
#define trigPin2 10
#define echoPin2 11
#define pwmOutput 6
#define CUSTOM_SETTINGS
#define INCLUDE_PUSH_BUTTON_SHIELD
#include "OneSheeld.h"
float duration, distance1, distance2;
int value;
void setup() {
  // put your setup code here, to run once:
  OneSheeld.begin();
  pinMode(trigPin1, OUTPUT);
  pinMode(echoPin1, INPUT);
  pinMode(trigPin2, OUTPUT);
  pinMode(echoPin2, INPUT);
  pinMode(pwmOutput, OUTPUT);

}

void loop() {
  // put your main code here, to run repeatedly:

  digitalWrite(trigPin1, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin1, HIGH);
  duration = pulseIn(echoPin1, HIGH);
  distance1 = (duration / 2) * 0.0343;
}

heres the error message:

In function 'global constructors keyed to 65535_0_AccelerometerSensorShield.cpp.o':

lto1.exe: 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.21.0_x86__mdqgnx93n4wtt\hardware\tools\avr/bin/avr-gcc returned 1 exit status

compilation terminated.

c:/program files/windowsapps/arduinollc.arduinoide_1.8.21.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 Uno.

it works fine when I delete the line with the “pulseIn” command. it also shows the error message when there is a “while” command inside the “void setup()”. so it looks like it shows this error for random function and commands.

This bug is specific to the 5.4.0-atmel3.6.1-arduino2 version of avr-gcc used by Arduino AVR Boards 1.6.22 and newer. It has been reported here:

Here's the traditional workaround:

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

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.

pert:
This bug is specific to the 5.4.0-atmel3.6.1-arduino2 version of avr-gcc used by Arduino AVR Boards 1.6.22 and newer. It has been reported here:
https://github.com/arduino/Arduino/issues/7949

Here’s the traditional workaround:

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

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.

I did it now I have 1.6.21 installed but the error still exists but the error message is now different I guess:

Arduino: 1.8.9 (Windows Store 1.8.21.0) (Windows 10), Board: "Arduino/Genuino Uno"

Build options changed, rebuilding all
avr-g++: error: cannot access device-specs for 'atmega328p' expected at 'device-specs/specs-atmega328p'

avr-g++: note: devices natively supported: ata5272 ata5505 ata5702m322 ata5782 ata5790 ata5790n ata5791 ata5795 ata5831 ata6285 ata6286 ata6289 ata6612c ata6613c ata6614q ata6616c ata6617c ata664251 ata8210 ata8510 atmega103 atmega128 atmega128a atmega128rfa1 atmega128rfr2 atmega1280 atmega1281 atmega1284 atmega1284p atmega1284rfr2 atmega16 atmega16a atmega16hva atmega16hva2 atmega16hvb atmega16hvbrevb atmega16m1 atmega16u2 atmega16u4 atmega161 atmega162 atmega163 atmega164a atmega164p atmega164pa atmega165 atmega165a atmega165p atmega165pa atmega168 atmega168a atmega168p atmega168pa atmega168pb atmega169 atmega169a atmega169p atmega169pa atmega256rfr2 atmega2560 atmega2561 atmega2564rfr2 atmega32 atmega32a atmega32c1 atmega32hvb atmega32hvbrevb atmega32m1 atmega32u2 atmega32u4 atmega32u6 atmega323 atmega324a atmega324p atmega324pa atmega325 atmega325a atmega325p atmega325pa atmega3250 atmega3250a atmega3250p atmega3250pa atmega328 atmega328p atmega328pb atmega329 atmega329a atmega329p atmega329pa atmega3290 atmega3290a atmega3290p atmega3290pa atmega406 atmega48 atmega48a atmega48p atmega48pa atmega48pb atmega64 atmega64a atmega64c1 atmega64hve atmega64hve2 atmega64m1 atmega64rfr2 atmega640 atmega644 atmega644a atmega644p atmega644pa atmega644rfr2 atmega645 atmega645a atmega645p atmega6450 atmega6450a atmega6450p atmega649 atmega649a atmega649p atmega6490 atmega6490a atmega6490p atmega8 atmega8a atmega8hva atmega8u2 atmega8515 atmega8535 atmega88 atmega88a atmega88p atmega88pa atmega88pb attiny10 attiny11 attiny12 attiny13 attiny13a attiny15 attiny1634 attiny167 attiny20 attiny22 attiny2313 attiny2313a attiny24 attiny24a attiny25 attiny26 attiny261 attiny261a attiny28 attiny4 attiny40 attiny43u attiny4313 attiny44 attiny44a attiny441 attiny45 attiny461 attiny461a attiny48 attiny5 attiny828 attiny84 attiny84a attiny841 attiny85 attiny861 attiny861a attiny87 attiny88 attiny9 atxmega128a1 atxmega128a1u atxmega128a3 atxmega128a3u atxmega128a4u atxmega128b1 atxmega128b3 atxmega128c3 atxmega128d3 atxmega128d4 atxmega16a4 atxmega16a4u atxmega16c4 atxmega16d4 atxmega16e5 atxmega192a3 atxmega192a3u atxmega192c3 atxmega192d3 atxmega256a3 atxmega256a3b atxmega256a3bu atxmega256a3u atxmega256c3 atxmega256d3 atxmega32a4 atxmega32a4u atxmega32c3 atxmega32c4 atxmega32d3 atxmega32d4 atxmega32e5 atxmega384c3 atxmega384d3 atxmega64a1 atxmega64a1u atxmega64a3 atxmega64a3u atxmega64a4u atxmega64b1 atxmega64b3 atxmega64c3 atxmega64d3 atxmega64d4 atxmega8e5 at43usb320 at43usb355 at76c711 at86rf401 at90can128 at90can32 at90can64 at90c8534 at90pwm1 at90pwm161 at90pwm2 at90pwm2b at90pwm216 at90pwm3 at90pwm3b at90pwm316 at90pwm81 at90scr100 at90s1200 at90s2313 at90s2323 at90s2333 at90s2343 at90s4414 at90s4433 at90s4434 at90s8515 at90s8535 at90usb1286 at90usb1287 at90usb162 at90usb646 at90usb647 at90usb82 at94k m3000

avr-g++: note: supported core architectures: avr2 avr25 avr3 avr31 avr35 avr4 avr5 avr51 avr6 avrxmega2 avrxmega4 avrxmega5 avrxmega6 avrxmega7 avrtiny avr1

avr-g++: note: you can provide your own specs files, see <http://gcc.gnu.org/onlinedocs/gcc/Spec-Files.html> for details

exit status 1
Error compiling for board Arduino/Genuino Uno.

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

This error means something went wrong during the installation of Arduino AVR Boards 1.6.21. You'll need to clear out the whole installation and install it over again. Please do this:

  • (In the Arduino IDE) File > Preferences
  • Click the link at the line following "More preferences can be edited directly in the file". This will open the Arduino15 (or similar name depending on OS) folder.
  • Delete all files and folders in that folder except for preferences.txt. Please be very careful when deleting things on your computer. When in doubt, back up!
  • (In the Arduino IDE) Close the Boards Manager window if it's open.
  • Tools > Board > Boards Manager
  • Wait for the 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".

pert:
This error means something went wrong during the installation of Arduino AVR Boards 1.6.21. You'll need to clear out the whole installation and install it over again. Please do this:

  • (In the Arduino IDE) File > Preferences
  • Click the link at the line following "More preferences can be edited directly in the file". This will open the Arduino15 (or similar name depending on OS) folder.
  • Delete all files and folders in that folder except for preferences.txt. Please be very careful when deleting things on your computer. When in doubt, back up!
  • (In the Arduino IDE) Close the Boards Manager window if it's open.
  • Tools > Board > Boards Manager
  • Wait for the 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".

did it but it shows the same error.. I did it a few times and one of the times the error message was only 1 line saying: "arduino.h no such directory or folder" but then it never showed it again on my next attempts. also when I open the board manager I have to try to open it a few times because it gets stuck and doesn't show the verisons tab and behaves very weird

Very strange. Are you out of hard drive space?

pert:
Very strange. Are you out of hard drive space?

space is more than enough, but I just moved the sketch location away from onedrive to some random location on the computer and now it works.. very strange that I was programming all good for a few months with the location being in onedrive and now all of the sudden it is a problem. I guess its something to do with the updates really

That is odd. There was a known bug with Onedrive with an older version of the Arduino IDE, but that caused a different error and it was fixed long before Arduino IDE 1.8.9 came out.

Anyway, I’m glad you managed to find a way to get it working. Enjoy!
Per