61

I recently installed CodeBlocks with mingw32 on Windows 7 Ultimate 32bit in order to dust off my c skills, but this problem has me somewhat stumped.

I decided to fire off a short Fibonacci generator to make sure my setup was working, but I ran into a hurdle.

The program compiles, links and whatnot like a charm and I get a corresponding executable which runs as expected.

The problems occur if I try to compile again, then I get the following:

c:/codeblocks/mingw/bin/../lib/gcc/mingw32/4.4.1/../../../../mingw32/bin/ld.exe: cannot open output file bin\Debug\Fibonacci.exe: Permission denied

I can't even edit the permissions of the generated executable.

I've checked the usual suspects:

  • Executable is verily not running.
  • Path to executable is read/writable to mingw32 (otherwise it wouldn't be able to build in the first place)
  • I'm not running cygwin in any shape or form.

And now for the funny bit: Usually after a few minutes, any executables generated by mingw32 which are displaying this Access Denied behaviour will automatically vanish without any intervention from me.

I've googled this somewhat, but most of the other results were either vague or inapplicable.

I wonder whether there is some Windows 7 security setting playing havoc with my .exe's, but I'm not that knowledgeable about Win 7 as to know where to begin searching.

Any one have any ideas?

  • 4
    Here's a total guess... if you're building to the bin\Debug directory then code::blocks may be doing something with its integrated debugger, keeping a file handle open on the executable. Try building it for release and see if you have the same problem – Rag Oct 05 '11 at 00:34
  • 1
    I think @BrianGordon's guess is a good one. If the program is running, kill it before trying to rebuild. – Keith Thompson Oct 05 '11 at 00:38
  • It behaves the same in Debug and Release and also if I run gcc from cmd. On a side note, it seems only to happen AFTER I actually run the executable. I'm starting to think it's definately a security settings thing. – Gissur Þórhallsson Oct 05 '11 at 01:04
  • After you run the executable? *Is it still running?* Does the program terminate by itself, or did you add something like a call to `getch()`? The linker can't write a new executable file if it's still being used. – Keith Thompson Oct 05 '11 at 04:21
  • No, if it's running, I can't find it anywhere in the Task Manager. It's not a terribly complicated program: http://pastebin.com/jYKs71uS – Gissur Þórhallsson Oct 05 '11 at 07:03
  • @gzzzur if you open explorer to the directory of the executable can you delete it when you get the permission denied error or does it issue an error that the file is still in use? – greatwolf Oct 05 '11 at 20:46
  • 2
    The executables vanish? As in they get deleted automatically? Sounds like a virus scanner issue. – tinman Oct 07 '11 at 12:40
  • 1
    Victor T. : I just get Permission denied tinman: No anti-virus installed, I just run mcafee stinger occasionally. I'm going to have a look at UAC tonight. – Gissur Þórhallsson Oct 07 '11 at 21:16
  • 1
    Your Code::Blocks Projects should not be created in directories like C , C://users//yourname or C://ProgramFiles or C://ProgramFiles/Code::Blocks. – 2147483647 Nov 05 '12 at 02:36

12 Answers12

47

I had exactly the same problem right after switching off some (in my opinion unneccessary) Windows services. It turned out that when I switched ON again the "Application Experience" everything resumed working fine.

May be you simply have to turn on this service? To switch ON Application Experience:

  1. Click the Windows start buttonn.

  2. In the box labeled "Search programs and files" type services.msc and click the search button. A new window with title "Services" opens.

  3. Right click on "Application Experience" line and select "Properties" from popup menu.

  4. Change Startup type to "Automatic (delayed start)".

  5. Restart computer.

Application Experiences should prevent the problem in the future.

Mahir Islam
  • 1,941
  • 2
  • 12
  • 33
Ralf
  • 494
  • 4
  • 2
  • 3
    This seems to be the actually good solution to this really nasty problem. I've seen it unsolved on some forum threads and the like. – Cimbali Nov 15 '12 at 16:36
  • Worked also for me, still I don't understand what's going on. – 5agado Apr 03 '14 at 14:16
  • 2
    Great answer came back after restart to +1 – Philip Rego Sep 25 '14 at 05:11
  • Worked for me as well, cannot explain it. – Robin Bruegger Mar 16 '15 at 16:45
  • I'm trying to build a software package with MSYS2/ming32 and encounter the same problem. I get the ld error when the configure script is trying to compile a test program. The "Application Experience" magic didn't work. – Seppo Enarvi Apr 14 '15 at 17:31
  • Worked even before restart on windows 7. Dont know why but it worked (; – Freak Jun 27 '16 at 11:37
  • 1
    In Windows 10, Application Experience can be found by:1. Go to the search in start menu and type task scheduler and select it from the list of results. 2. In there, please select the Task scheduler library in the left pane. 3. There select Microsoft. 4. In Microsoft, please select Windows. 5. In the Windows, please select the Application Experience. (From [this form](https://answers.microsoft.com/en-us/windows/forum/windows_10-other_settings-winpc/where-can-i-find-application-experience-service-in/a499361b-b7c5-46d1-81c3-15a098860446)) – Pro Q May 30 '18 at 12:02
  • For me, Cortana = search. However, once I get to that screen I'm not sure what to do to restart "Application Experience". – Pro Q May 30 '18 at 12:05
  • Worked for me, it wasnt the antivir/git, Windows is just the worst! – Vincent Alex Nov 19 '22 at 16:12
29

Your program is still running. You have to kill it by closing the command line window. If you press control alt delete, task manager, process`s (kill the ones that match your filename).

Community
  • 1
  • 1
plodoc
  • 2,783
  • 17
  • 17
23

If you think the executable is locked by a process, try Process Explorer from SysInternals. In the File/handle, enter Fibonacci.exe and you should see who holds the file.

If it is not enough, you can use Process Monitor (from SysInternals, again) to follow the activity of all processes on your system on Fibonacci.exe. With a little bit of analysis (call stacks), you'll may find out why the access to the file is denied and what make it disappear.

Thierry Franzetti
  • 1,763
  • 12
  • 12
  • I picked your answer because it looks like the most plausible solution given my problem statement. I wasn't able to try it out though, since the machine I had it running on crashed. Since I've now decided to go with linux it kind of makes this a moot point for me. – Gissur Þórhallsson Oct 25 '11 at 13:50
10

Problem Cause : The process of the current program is still running without interuption. (This is the reason why you haven't got this issue after a restart)

The fix is simple : Go to cmd and type the command taskkill -im process_name.exe -f

Eg:

 taskkill -im demo.exe -f

here,

demo - is my program name

Arun Joseph
  • 2,736
  • 25
  • 35
7

The Best solution is go to console in eclipse IDE and click the red button to terminate the program. You will see the your program is running and output can be seen there. :) !!

Black_Rider
  • 1,465
  • 2
  • 16
  • 18
4

I had the same behaviour, and fixed it by running Code::Blocks as administrator.

Matt Fenwick
  • 48,199
  • 22
  • 128
  • 192
Luis
  • 41
  • 1
3
  1. Open task manager -> Processes -> Click on .exe (Fibonacci.exe) -> End Process

    if it doesn't work

  2. Close eclipse IDE (or whatever IDE you use) and repeat step 1.

Khokhar
  • 685
  • 1
  • 9
  • 22
2

I had a similar problem. Using a freeware utility called Unlocker (version 1.9.2), I found that my antivirus software (Panda free) had left a hanging lock on the executable file even though it didn't detect any threat. Unlocker was able to unlock it.

  • Thanks, I was able to fix the same problem by turning off File System Auto-Protect from Symantec Endpoint Protection. – Seppo Enarvi Apr 14 '15 at 17:38
2

Got the same issue. Read this. Disabled the antivirus software (mcaffee). Et voila

Confirmed by the antivirus log:

Blocked by Access Protection rule d:\mingw64\x86_64-w64-mingw32\bin\ld.exe d:\workspace\cpp\bar\foo.exe User-defined Rules:ctx3 Action blocked : Create

Hey StackExchange
  • 2,057
  • 3
  • 19
  • 35
2

It may be your Antivirus Software.

In my case Malwarebytes was holding a handle on my program's executable:

enter image description here

Using Process Explorer to close the handle, or just disabling antivirus for a bit work just fine.

  • [SOLVED]In my case it was the anti-virus that was blocking it. I opened the antivirus program and it had logged an event that ld.exe was blocked. If you just add the exception to ld.exe, this error goes away, no need to disable Antivirus. – Chandan May 12 '18 at 23:37
1

i experienced a similar issue. Bitdefender automatically quarantined each exe-file i created by MinGW g++. Instead of the full exe-file i found a file with a weird extension 'qzquar' testAutoPtr1.exe.48352.gzquar

When i opened quarantined items in Bitdefender i found my exe-file quarantined there.

0

I got this error when using the Atom editor and mingw (through a package called gpp-compiler) for C++. Closing the open console window fixed my issue.

Pro Q
  • 4,391
  • 4
  • 43
  • 92