Cannot open output file, permission denied

C++Compiler ErrorsCodeblocksPermission Denied

C++ Problem Overview


So I keep getting this error when trying to compile C++ code using CodeBlocks.

> cannot open output file [filename.exe] permission denied

It only started today, and it's sporadic and inconsistent. It usually goes away if I shut CodeBlocks down and restart the project, but not always. Sometimes it even goes away when I just press F9 (build & run) several times. I always check Task Manager, but there are never any .EXEs running with my file's name, or anything related to it.

I've also noticed that if this problem occurs and I then try to delete the .EXE manually or otherwise interact with it, Windows tells me I need administrator permission to do so (this is a private PC, and as far as I know I am an administrator on it).

The first time it occurred, the only thing I had added to the code beyond what was in the previous version was a debugging report sent to cout - hardly anything arcane. It sometimes occurs even when no code was changed from a previous version.

What could this be? It's not game-breaking, yet, but it's irritating and I'd rather it didn't get worse.

EDIT: This is old by now, but just in case anyone else is having similar problems, the workaround I currently use is just to consistently delete [filename.exe] before trying to run the code again. This avoids the problem, though it is annoying.

C++ Solutions


Solution 1 - C++

check that "filename.exe" is not running, I guess you are using Microsoft Windows, in that case you can use either Task Manager or Process Explorer : http://technet.microsoft.com/en-us/sysinternals/bb896653 to kill "filename.exe" before trying to generate it.

Solution 2 - C++

I have encountered the same problem you have. I found that it may have some relationship with the way you terminate your run result. When you run your code, whether it has a printout, the debugger will call the console which print a "Press any key to continue...". If you terminate the console by pressing key, it's ok; if you do it by click the close button, the problem comes as you described. When you terminate it in the latter way, you have to wait several minutes before you can rebuild your code.

Solution 3 - C++

I just had the same issue. And i experienced that it always happens when i run the programm and change some code without finishing the programm still running. After that the "cannot open ..." message appears.

However i got rid of it by clicking the "Terminate" button at the very top-right side of the console window (red button) and after that "remove all terminated launches" (two x'es right next to the terminate button). This seems to close the running programm and everything works fine after :) hope this may help anyone

Solution 4 - C++

I was having the same problem too and it was driving me crazy:

Windows7 64 bit, MinGW, Eclipse, CDT

Permission denied errors, executable disappearing, ld.exe errors. It would work once, but never again. Statements like: "cannot open output file ***.exe: Permission denied"

Check your ANTIVIRUS Software. Once I turned off my Antivirus software in workspace then cleaned the workspace and started the project over again I never had the problem again.

Solution 5 - C++

This error usually occurs when the IDE has a problem due to a crash or other failure and it still has a hold on the EXE, preventing the user (yourself) from overwriting / deleting the EXE during a rebuild.

Solution 6 - C++

Hello I realize this post is old, but here is my opinion anyway. This error arises when you close the console output window using the close icon instead of pressing "any key to continue"

Solution 7 - C++

The problem is related to Sam´s response:

> "have encountered the same problem you have. I found that it may have > some relationship with the way you terminate your run result. When you > run your code, whether it has a printout, the debugger will call the > console which print a "Press any key to continue...". If you terminate > the console by pressing key, it's ok; if you do it by click the close > button, the problem comes as you described. When you terminate it in > the latter way, you have to wait several minutes before you can > rebuild your code."

Avoid kill processes, and we have two choices, wait until the process release the .EXE file or this problem will be solved faster restarting the IDE.

Solution 8 - C++

You can use process explorer from sysinternals to find which process has a file open.

Solution 9 - C++

Try restarting your IDE. It worked for me. Although I tried to end the process in the task manager, the process never got killed.

Solution 10 - C++

I re-installed C::B in drive D, whereas my program files folder is in drive C

I don't know the reason , but it works :)

Solution 11 - C++

well,once i had the same problem and after tracking down the process that was getting the file in use i discovered that it was the anti-virus (PANDA) ...i just unlocked the file and simply worked out ....well for my experience i used Unlock 1.9.2 ...try iy out ..

Solution 12 - C++

A major cause of this (which I had recently), is if you have this on for example a flash drive.

You can develop and do everything, but on most systems it stops you from running the .exe file from there, whether it be the debug or release version.

Solution 13 - C++

In my case - I found a process called

cb_console_runner

I stopped this process and things were ok again.

Solution 14 - C++

FOR LINUX OS... go to file where u r created file.then usually ......project_name/bin/Debug/project_name.executable here for this executable file you wont be having execute permission then the execute permission.Either by right click if you are unable to change permission then use use open terminal(command promt) to change permission. first go to that executable file using 'cd' command then use "chmod u+x" then permission is going to change.then go to c::b open and execute you will get output.

only thing for all file u need to do it.

Solution 15 - C++

The problem is that you don't have the administrator rights to access it as running or compilation of something is being done in the basic C drive. To eliminate this problem, run the devcpp.exe as an administrator. You could also change the permission from properties and allowing access read write modify etc for the system and by the system.

Solution 16 - C++

Make sure to run 7zip in 'Administrator mode' for extracting to Program Files.

Also, temporarily turning off virus protection worked for some people in the past.

Solution 17 - C++

I tried what @willll said, and it worked. I didint find exactly the .exe named after my project, but I did kill some weird looking tasks (after checking on the internet they were not critical), and it worked.

Solution 18 - C++

I have tried and get output after end task IDE from task manager. Later clean all temporary files from your drive. Start your IDE. Now your .exe working good.

Solution 19 - C++

I had the same Problem. Just rename your .CPP file to other name and try it again. It worked for me.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionGarrickWView Question on Stackoverflow
Solution 1 - C++willllView Answer on Stackoverflow
Solution 2 - C++SamView Answer on Stackoverflow
Solution 3 - C++LaiebiView Answer on Stackoverflow
Solution 4 - C++FirefishView Answer on Stackoverflow
Solution 5 - C++user195488View Answer on Stackoverflow
Solution 6 - C++user2203361View Answer on Stackoverflow
Solution 7 - C++JorgesysView Answer on Stackoverflow
Solution 8 - C++Chris CardView Answer on Stackoverflow
Solution 9 - C++NamrathaView Answer on Stackoverflow
Solution 10 - C++user2776580View Answer on Stackoverflow
Solution 11 - C++afr0ckView Answer on Stackoverflow
Solution 12 - C++EternalWulfView Answer on Stackoverflow
Solution 13 - C++Wolfgang AdamecView Answer on Stackoverflow
Solution 14 - C++chetan hView Answer on Stackoverflow
Solution 15 - C++KaranView Answer on Stackoverflow
Solution 16 - C++EfreetoView Answer on Stackoverflow
Solution 17 - C++J3STERView Answer on Stackoverflow
Solution 18 - C++sudharsan chandrasekaranView Answer on Stackoverflow
Solution 19 - C++Ahmad AsmndrView Answer on Stackoverflow