Fatal Error: Cannot create output file "project1.exe"

45,934

Solution 1

I found the solution. It appears that disabling the service "Application Experience" caused this. When disabled the task "system" will lock "any" executable for some time.

Re-enabling "Application Experience" is the solution.

Found via:

https://superuser.com/questions/260375/why-would-system-continue-locking-executable-file-handles-after-the-app-has-exit

Solution 2

I have the feeling that when you try to rebuild the application, project1.exe is still running. Maybe it takes longer than it should to close. You can easily check by opening Task Manager and see if the process project1.exe is still active after you close the application.

Solution 3

I'm on XE7 and occasionally experience the "Could not create output file" problem, . Using sysinternals' Process Explorer, I discovered an android debug process (adb.exe) had a lien on the compiled binary. Not sure why; there's no android config in this particular win32 project I'm building. Anyway, killed adb.exe and all was good thereafter.

Some points. The target output directories were never being indexed. "Application Experience" mentioned elsewhere in this thread was running the entire time. And most of the time, I could manually delete the output binary despite XE7's complaints. I noticed at one point, however, I could not delete the binary via the shell which provided the opportunity to locate the offending adb.exe via Process Explorer.

Solution 4

I faced the same problem and I solved it . It seems that in some unknown cases the exe application remains running .
The solution is simple . You must just follow the following steps :

  1. open the windows task manager
  2. Go to the 'Processes' tab
  3. click on the 'Show processes from all users' and Your exe will appear
  4. Choose it and press the 'End Process' button

And everything will be alright.

Solution 5

I right clicked the application (in the project group window) and then selected CLEAN.

I was then able to compile the application.

Share:
45,934
Marck
Author by

Marck

Updated on September 17, 2021

Comments

  • Marck
    Marck over 2 years

    So for some time now I keep having this problem:

    on windows 7 (64bit), with Delphi 7 and Delphi XE2, if from within the IDE, I compile a program, run it, stop it, change it and rerun it I get this error message:

    [Fatal Error] Cannot create output file "project1.exe"

    I have no clue to what causes this. I googled for more information, but I could not find a solution.

    There are two workarounds: either wait a minute or two, or delete project1.exe manually. Needless to say, this is unworkable.

    I do not have a virus scanner, and no virus. Have full access to related folders. Run everything as Administrator.

    So what causes this? And what can I do to fix it?

  • Marck
    Marck almost 12 years
    No it is not (unless for some magical reason, pressing ctrl+f2 or closing the app, would not close the app on windows 7)
  • Diego
    Diego almost 12 years
    That's why I suggested to check. Also, the file may be in use by Windows built-in anti malware solution, called Microsoft Security Essentials. Sometimes it's annoying, it seems to lock files "just because".
  • Ken White
    Ken White almost 12 years
    If waiting a minute or two fixes it, it most likely is caused by the reason Diego mentions. You can check yourself by watching it in the Task Manager processes tab (not the Applications tab) - start Task Manager, find your app in the processes tab, switch back to Delphi and stop your application. See how long it takes to go away in Task Manager. BTW, Ctrl+F2 should be used as a last resort to halt your app; the best way is to shut it down normally instead unless something has hung it up or put it into an endless loop or something.
  • Marck
    Marck almost 12 years
    @Diego: I don't have MSE. But you're right, something is locking it. But what? And why only windows 7?
  • Marck
    Marck almost 12 years
    @Ken: I have used ctrl+f2 since day 1. I disagree with "should be used as a last resort". In any case, the app is gone, I'm not doing anything different than I have been doing for ages.
  • Ken White
    Ken White almost 12 years
    @Marck: Ctrl+F2 is "forceful termination", which means resources may not get properly released, databases may not be properly closed, etc. Normal termination is always cleaner and better than forced termination. Regardless of that, the only time I have ever (since Delphi 1 was released) encountered the problem you describe is by having the app not fully shut down from the prior run (or forgetting to terminate it myself before fixing an issue in the code and trying to compile again, like sometimes happens when single-stepping through code and seeing the issue).
  • Marck
    Marck almost 12 years
    @Ken: listen, don't tell me not to press ctrl+f2. It happens eitherway. Start delphi, new project, run, press close, put a button on the form, press run, voila "cannot create..." there is nothing in task manager running. (Would surprise too that delphi suddenly would return you to the ide while the app is still running)...
  • Diego
    Diego almost 12 years
    @Marck I understand that probably it won't make any difference in your case, but the fact that you have used CTRL+F2 from day 1 doesn't make it a good practice. It's always better to shut down an application gracefully, rather than "kill" it. Regarding the what is locking your file, you can use tools such as LockHunter or Process Explorer and see what other process put a lock on your file.
  • Ken White
    Ken White almost 12 years
    @Marck: I don't understand the hostility. I didn't say "Don't do it"; I suggested you not do it. There's a difference between "ordering someone" and "making a suggestion". I apologize for trying to offer you constructive advice - I certainly didn't mean to offend you. I promise to try very hard not to offer to help you in the future. Good luck solving this and your future problems.
  • Marck
    Marck almost 12 years
    @Ken: there is no hostility, I just resent sidetracking. You can offer all the assistance, tips you want, but it doesn't solve the problem.
  • Marck
    Marck almost 12 years
    @Diego: I downloaded and used both tools. Neither of them show anything. For delphi 7 I seem to have fixed it. I changed compatibility settings to xp sp2. Problem gone. But the question still stands, what is causing this behaviour in w7 mode....
  • Arioch 'The
    Arioch 'The almost 12 years
    antivirus ? run Process Monitor, filter for fiel access and path to your exe and track who ever has or had accessed it.
  • Marck
    Marck almost 12 years
    No, no antivirus, no virus. I was wrong saying that process explorer doesn't show anything. It actually shows the process "System" locking the file. However "system" is (part of) the windows7 kernel. So googling on this I found the solution.
  • Marcelo Bergweiler
    Marcelo Bergweiler over 9 years
    Worked for me too! This is the hint of the year, I was having this problem for a long time. I was wondering how to programatically emulate a manual file deletion, if this makes sense to you.
  • Wh1T3h4Ck5
    Wh1T3h4Ck5 over 9 years
    I usually forget to close EXE after compile and this happens. That was my guess too :D
  • Jerry Dodge
    Jerry Dodge over 9 years
    This has been soooooo annoying for me in Delphi XE7, on 3 different computers. Never happened on other versions I've used (including 7, 2010, and XE2). Glad to know this fix. At least on my main IDE machine I've changed this, now waiting to see if it happens again.
  • Eric Fortier
    Eric Fortier over 9 years
    Kudos to whoever found the solution, I would never have in a million years. I reinstalled XE7 many times trying to fix this. Goes to show that turning services off trying to make things go smoother can have the opposite effect.
  • bvj
    bvj about 9 years
    The problem is often more insidious than a belligerent zombie. In many cases, the problematic binary can be manually deleted from the output folder which normally requires any dependent processes not be running.
  • Thomas
    Thomas over 8 years
    I have the same problem in Windows 10 (with XE8) but the "Application Experience" does not exist.
  • costa
    costa over 8 years
    Hey, I had the same problem. The accepted answer didn't work for me, however, after I disabled Castalia the issue disappeared. I am using XE8.
  • GJ.
    GJ. almost 8 years
    Thanks for that. I have the same problem with Delphi 10.1 Berlin
  • Admin
    Admin over 7 years
    It doesn't work for me. I'm using Delphi 10.1 Berlin.
  • David Cornelius
    David Cornelius over 7 years
    Thank you!! This was the solution for me as well. I know this was posted over 4 years ago now, but I finally typed in the right search criteria and found it. This has plagued me for a long time in several versions of Delphi and three versions of Windows. I have not seen this problem with Visual Studio but I think that's a testament to Delphi's quick edit-compile-debug-edit-recompile cycle: it's a fast IDE!
  • David Cornelius
    David Cornelius over 7 years
    I have Castalia installed, so disabled and restarted Delphi with the same problem. The "Application Experience" solution was the key for me.
  • MartynA
    MartynA over 5 years
    This would be a better answer if it explained why disabling "Application Experience" overcomes the OP's problem, despite your answer seeming to directly contradict the accepted answer by MarcK.
  • Paulo França Lacerda
    Paulo França Lacerda almost 5 years
    Worked for me (Delphi 10.3 Rio on Windows 7 x64). :D
  • Reversed Engineer
    Reversed Engineer over 4 years
    Downvoting without leaving a comment is extremely bad form. I'll delete this message if the downvoter says why