IDE fail "...rename 'core\core.a'; reason: File exists" or "reference to main"

I am having a lot of trouble with the IDE not compiling. Windows 10, IDE 1.8.5, board is a Pro Micro 32U4. Program is:
void setup() {
// put your setup code here, to run once:
void loop() {
// put your main code here, to run repeatedly:

If I change to UNO it compiles. Change to Leonardo, it doesn't until suddenly it does. Then I am ok for awhile, but then it doesn't. It does not matter what is in the sketch - I am just using an empty sketch to provide a smoking gun to the problem.

c:/program files (x86)/arduino/hardware/tools/avr/bin/../lib/gcc/avr/4.9.2/../../../../avr/lib/avr5/crtatmega32u4.o:(.init9+0x0): undefined reference to `main'

collect2.exe: error: ld returned 1 exit status

exit status 1
Error compiling for board Arduino Leonardo.

Sometimes I get this message:

c:\programfiles(x86)\arduino\hardware\tools\avr\bin../lib/gcc/avr/4.9.2/../../../../avr/bin/ar.exe: unable to rename 'core\core.a'; reason: File exists

It might be caused by your antivirus scanning newly created files. The solution would be to whitelist the problematic folders/programs.