Project won't build when using upload

I’ve been running into an issue for over a year now and its very annoying. First off I’ll say the underlying problem could be that I have some circular header references, but I’m not sure.

Occasionally the build process fails to find a dependancy in my library folder that was previously found. Simply changing one line in any file is enough to trigger this.

Now the project will build okay using the build command and produce a hex file, but if I try and upload the project, platformio wants to rebuild the project before uploading and it fails. This is consistent and reproducible. What is going on? Why does upload want to recompile the program?

With respect to the circular references I have include guards. However, I’m thinking that instead of having the header file for each of my libraries in each separate folder I should put them in the include folder. Would this help? Thanks.

Please post here your platformio.ini.

[env:megaatmega2560]
platform = atmelavr@1.9.0
board = megaatmega2560
framework = arduino
lib_deps =
Timer@7b408e8131
StepperDriver@1.1.3
swRTC@1.2.9
ArduinoJson@5.13.2
PGMWrap@1.0.0
EEWrap@1.0.0
upload_port = com7
build_flags =
-Wall
-D SERIAL_RX_BUFFER_SIZE=128
-D SERIAL_TX_BUFFER_SIZE=128
; -D DEBUG_MEGA_PORT=Serial1
; -D RAM_GET_SET
; -D CMD_DEBUGGING
; -DSTEPPER
; -D MOTOR_STEPS=200
; -D FILL_RPM=300
; -D DOSE_RPM=300
; -D PRIME_STEPS=6000
-D PRIME_TIME=500UL
-D DOSE_TIME=7000
-D DOSE_VOLUME=30.0f
-D Acond=7.08e-9f
-D Bcond=3.42e-5f
-D Ccond=0.0591f
-D Dcond=46.05f
-D Econd=14118.0f
-D Cv=0.24f
-D MLP=0.45f
-D BETA=3349.0f
-D ADCMAX=1023.0f
-D HW_VER_DEF=“1.3”
-D SW_VER_DEF=“0.9.9”
-D DATA_VER_DEF=“0.9”
-D DATA_VER_MAX_SZ=33
-D MAX_PRIMES_ALLOWED=9
-D MAX_PURGE_TIME=600UL
-D BROADCAST_INTERVAL=3000UL
-D RTC_TIMEOUT=3000UL
-D TT3_MAX=39.0f