avr-gcc.exe: The filename or extension is too long.

fork/exec C:\Users\tom4p\AppData\Local\Arduino15\packages\arduino\tools\avr-gcc\5.4.0-atmel3.6.1-arduino2/bin/avr-gcc.exe: The filename or extension is too long.
Error compiling for board Arduino/Genuino Mega or Mega 2560.

I am getting the above error message while compiling the code.

I have seen comments on various websites like changing the temp folder from %temp% to C:\temp. But I don't know where and how to apply this fix? Can anyone please help me out with this issue.


Which version of the Arduino IDE are you using? Some recent work was done to ensure this problem doesn't happen.