I know this has been asked a lot but in most cases the answers were non quite satisfying/working, so I'll try to give it another shot:
In my C++ project which is being built by Eclipse CDT using MinGW with GCC, I have the following pre- and post-build steps:
- pre: delete myapp.exe from central "dist" folder (in case an old version is lying around)
- build: compile myapp.exe
- post: move the compiled myapp.exe from the configuration's folder to central "dist"
So far so good, but here's the problem:
When I quickly recompile the application the delete and move/overwrite steps (pre and post) fail with a "permission denied" message. However, after a while the file is gone so I assume some delete command is waiting in the background until the permission is granted.
This is quite annoying, especially since I can't just make a change, recompile and test.
The answers I found so far mostly consist of the following:
- the application might still be running
-> I never started it after compiling, so I guess it's not running - some other application might hold a handle to the file
-> ProcessExplorer doesn't find any open file handle to myapp.exe (though there might be one, but how would I find it?) - some antivirus might be checking the new file
-> I specifically put the "dist" folder on the ignored pathI - the permissions might be missing
-> I'm trying this as administrator, so user permissions should not be an issue
Any ideas of what additional things I could check?
Btw, I'm doing this on a Win7 machine, in case it does matter.
Update:
I tried to compile the app twice and then tried to delete the exe on the command line. Message: permission denied.
Here's the Process Monitor output (command was D:\Development\dist>del myapp.exe
):
23:46:16,6973545 cmd.exe 3716 QueryOpen D:\Development\dist\myapp.exe DELETE PENDING
23:46:16,6974731 cmd.exe 3716 QueryOpen D:\Development\dist\myapp.exe DELETE PENDING
23:46:16,6975989 cmd.exe 3716 CreateFile D:\Development\dist SUCCESS Desired Access: Read Data/List Directory, Synchronize, Disposition: Open, Options: Directory, Synchronous IO Non-Alert, Attributes: n/a, ShareMode: Read, Write, Delete, AllocationSize: n/a, OpenResult: Opened
23:46:16,6976533 cmd.exe 3716 QueryDirectory D:\Development\dist\myapp.exe SUCCESS Filter: myapp.exe, 1: myapp.exe
23:46:16,6977718 cmd.exe 3716 CreateFile D:\Development\dist\myapp.exe DELETE PENDING Desired Access: Read Attributes, Delete, Disposition: Open, Options: Non-Directory File, Open Reparse Point, Attributes: n/a, ShareMode: Read, Write, Delete, AllocationSize: n/a
23:46:16,6978960 cmd.exe 3716 CreateFile D:\Development\dist\myapp.exe DELETE PENDING Desired Access: Read Attributes, Delete, Disposition: Open, Options: Non-Directory File, Open Reparse Point, Attributes: n/a, ShareMode: Read, Write, Delete, AllocationSize: n/a
23:46:16,7655834 cmd.exe 3716 QueryDirectory D:\Development\dist NO MORE FILES
23:46:16,7656301 cmd.exe 3716 CloseFile D:\Development\dist SUCCESS
So it seems as if the file is blocked because a delete is pending. I'll check the pre-build command tomorrow.