I am using latest Pio and have problems with final linking failing. I have reverted to Python 3.7.7 and it gets further, but not complete. In the error, I saw “lto” mentioned. I inserted build_unflags = -flto. Here is a snip of the final compile, and it looks like the flag was not removed.
avr-g++ -o .pio\build\megaatmega2560\firmware.elf -Os -mmcu=atmega2560 -Wl,--gc-sections -flto -fuse-linker-plugin .pio\build\megaatmega2560\src\CRC32.cpp.o .pio\build\megaatmega2560\src\ContactManagementFunctions.cpp.o .pio\build\megaatmega2560\src\DiagnosticFunctions.cpp.o .pio\build\megaatmega2560\src\GSMFunctions.cpp.o .pio\build\megaatmega2560\src\MegaMaster.cpp.o .pio\build\megaatmega2560\src\MonitoringFunctions.cpp.o .pio\build\megaatmega2560\src\SlaveCommunicationFunctions.cpp.o .pio\build\megaatmega2560\src\Sounds.cpp.o .pio\build\megaatmega2560\src\WatchdogFunctions.cpp.o -L.pio\build\megaatmega2560 -Wl,--start-group .pio\build\megaatmega2560\libe03\libSPI.a .pio\build\megaatmega2560\libf01\libEthernet_ID872.a .pio\build\megaatmega2560\lib421\libSerialGSM.a .pio\build\megaatmega2560\libc98\libSdFat_ID322.a .pio\build\megaatmega2560\liba74\libWire.a .pio\build\megaatmega2560\libFrameworkArduinoVariant.a .pio\build\megaatmega2560\libFrameworkArduino.a -lm -Wl,--end-group
C:\Users\Owner\AppData\Local\Temp\ccVwudPP.ltrans1.ltrans.o: In function `main':
<artificial>:(.text.startup+0x76c): undefined reference to `notifyContactsAlarmResponse(int)'
C:\Users\Owner\AppData\Local\Temp\ccVwudPP.ltrans0.ltrans.o: In function `checkIncomingSMS() [clone .part.1] [clone .lto_priv.76]':
<artificial>:(.text+0x446): undefined reference to `notifyContactsAlarmResponse(int)'
collect2.exe: error: ld returned 1 exit status
*** [.pio\build\megaatmega2560\firmware.elf] Error 1
==================== [FAILED] Took 51.97 seconds ====================
PS C:\Users\Owner\Documents\PlatformIO\Projects\Alarm2>