1

I have an error which started showing up only a few days ago. I'm running Windows 7 Professional x64 bit.

I have a .cpp file, and I use the command prompt to run the following command:

g++ -std=c++11 A.cpp

It creates the executable, a.exe. However if I run the same command again immediately, I get this error:-

c:/mingw/bin/../lib/gcc/mingw32/5.3.0/../../../../mingw32/bin/ld.exe: cannot 
open output file a.exe: Permission denied
collect2.exe: error: ld returned 1 exit status

If I try to delete the executable, I get "You need permission to perform this action" (I'm using an Administrator account). Under the security tab in properties, it says "Unable to display current owner." If I try to change it's ownership, I get "Unable to set a new owner on a.exe. Access is denied."

Furthermore, if I try to open the file, it says "Windows cannot access the specified device, path or file. You may not have the appropriate permissions to access the item."

Strangest of all, after about a minute the file then automatically disappears.

None of these happen if I run the compile command just once. If I run it once, I can delete the executable, run it, and the owner displays my account name. The file also doesn't disappear.

Please help me with this, it's very annoying. I tried with my anti virus (Kasperksy Internet Security) turned off, and this still happens.

2
  • Guess - bad code or something else delaying g++? Because these syptoms sound like g++ is taking a minute to compile the executable and you are trying to do things with it while g++ is still working. Commented Jun 27, 2017 at 18:49
  • If I compile just once, it compiles immediately and runs fine too. So I don't think g++ is taking too long to compile.
    – Cerberus
    Commented Jun 28, 2017 at 21:33

2 Answers 2

1

I found this thread on this website, and while the problem listed is a bit different the solution (Enable the "Application Experience" service and set it to "Automatic".) worked for me.

0

Is an anti-malware tool checking the newly-created executable and locking it? Is it the g++ application that has it locked?

Try a third-party tool to check what is causing the file to be locked, such as LockHunter. It should show what processes have a handle open for that file.

Another possibility: Windows Search indexing, which has locked Thunderbird message deletion for minutes. Disabling Search or excluding all foilders used by g++ would help confirm that.

2
  • I tried using Unlocker, it says nothing is locking. But if I tell Unlocker to delete, it can't. Also I've tried doing all this with my anti virus disabled, and I don't have any other anti-malware tool installed.
    – Cerberus
    Commented Jun 28, 2017 at 21:32
  • If it's not Windows Search, either, try another third-party lock tool... alternativeto.net/software/lockhunter Commented Jun 28, 2017 at 23:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .