I'm having the same issues as the post below, but the thread is closed so I can't add to it:
I'm having this same problem.
The two strangest elements of this issue are "I know the error is not in my code because the same code will compile satisfactorily at some point" and "And it happens with working progams, so it isn't an error in my code. And it seems to be quite random"
In the other post, they asked if one had googled and then provided a link. The link provided no insight as to what was actually causing the error but instead said, basically, "delete the contents of the build directory".
Looking at other google results are similarly not illuminating. One response on StackOverflow suggested that one's path might have paths that are confusing to the IDE in finding the MinGW stuff. I'm not sure what constitutes confusing, but I looked at my path and nothing leapt out as being related to MinGW (though, again, the guidance is not super educational, so I'm not sure what to look for).
Luckily, In my case, the issue never causes me to reboot my machine (which is a problem that the OP reports). For me, I can simply tell Arduino to compile again and the problem usually doesn't happy twice in a row.
But what is the cause? How can it be made to not happen anymore?