16

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?

RRUZ
  • 130,998
  • 15
  • 341
  • 467
Marck
  • 666
  • 1
  • 5
  • 12

14 Answers14

16

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

Community
  • 1
  • 1
Marck
  • 666
  • 1
  • 5
  • 12
  • 1
    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. – Marcelo Bergweiler Aug 30 '14 at 00:38
  • 1
    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. – Jerry Dodge Jan 12 '15 at 06:10
  • 1
    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. – Eric Fortier Jan 13 '15 at 19:51
  • 2
    I have the same problem in Windows 10 (with XE8) but the "Application Experience" does not exist. – Thomas Sep 01 '15 at 07:12
  • 1
    Thanks for that. I have the same problem with Delphi 10.1 Berlin – GJ. Jun 07 '16 at 22:07
  • It doesn't work for me. I'm using Delphi 10.1 Berlin. –  Aug 30 '16 at 07:35
  • 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 Oct 24 '16 at 02:53
  • Worked for me (Delphi 10.3 Rio on Windows 7 x64). :D – Paulo França Lacerda Jul 05 '19 at 17:34
5

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.

Diego
  • 6,134
  • 4
  • 28
  • 36
  • No it is not (unless for some magical reason, pressing ctrl+f2 or closing the app, would not close the app on windows 7) – Marck Aug 07 '12 at 18:15
  • 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". – Diego Aug 07 '12 at 18:19
  • 3
    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. – Ken White Aug 07 '12 at 18:21
  • @Diego: I don't have MSE. But you're right, something is locking it. But what? And why only windows 7? – Marck Aug 07 '12 at 18:24
  • @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. – Marck Aug 07 '12 at 18:25
  • @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). – Ken White Aug 07 '12 at 18:29
  • 1
    @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)... – Marck Aug 07 '12 at 18:41
  • @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](http://lockhunter.com/) or [Process Explorer](http://technet.microsoft.com/en-us/sysinternals/bb896653.aspx) and see what other process put a lock on your file. – Diego Aug 07 '12 at 18:48
  • 4
    @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. – Ken White Aug 07 '12 at 19:07
  • @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 Aug 07 '12 at 19:21
  • @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.... – Marck Aug 07 '12 at 19:22
  • antivirus ? run Process Monitor, filter for fiel access and path to your exe and track who ever has or had accessed it. – Arioch 'The Aug 08 '12 at 05:53
  • 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. – Marck Aug 08 '12 at 07:34
  • I usually forget to close EXE after compile and this happens. That was my guess too :D – Wh1T3h4Ck5 Dec 26 '14 at 02:44
4

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.

bvj
  • 2,846
  • 27
  • 26
3

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.

bummi
  • 26,435
  • 13
  • 58
  • 97
  • 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. – bvj Feb 17 '15 at 10:25
1

Try removing Castalia if you are using it. I spent 3 days trying to solve this problem, everything I could think of...file permissions, watching the file handles with process explorer. If I install Castalia 2013.3.4, the problem happens (I have steps to reproduce), and uninstalling it makes the problem go away.

Additionally, the IDE will crash if you have a 'default debug desktop' set, and try to run under the debugger using any other saved layout. (crash happens on the switch to the debug desktop).

  • 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. – costa Nov 20 '15 at 20:53
  • I have Castalia installed, so disabled and restarted Delphi with the same problem. The "Application Experience" solution was the key for me. – David Cornelius Oct 24 '16 at 02:56
1

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

I was then able to compile the application.

kidjake28
  • 11
  • 1
1

In my case Problem solved by excluding project folder from antivirus real time protection.

Can you delete EXE file manually?If no , proccess is in memroy , Open task manager ,select your project, END task . you have some bug in code that prevents application terminate.

If it is not in process list , Then Try :

1-exclude folder from windows Indexing or 3rd party file search applications that index files

2-In windows seven activate application experince service

3-Exclude project folder from Anti virus realtime protection

UPDATE

I noticed that ,Even if you do all what i said above, you may get this error some times in Windows 7 randomly.specially when you compile project many times...first compiles will be OK but after ten or more times this problem will be occurred

1

Watch this link :
How to fix Error : [dcc32 Fatal Error] F2039 Could not create output file X

Only you most put this command to all projects.

MohsenB
  • 1,223
  • 14
  • 27
  • 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. – MartynA Nov 30 '18 at 19:48
0

Sometimes Microsoft Security Essentials holds the file after it was build in Delphi and you need to turn off real time protection.

To check which process holds the file, use Sysinternals Process Explorer: link. Use "Find handle" and type your exe name.

0

In my case it was due to the output folder that did not exist.

So what you can try is go to Project-> Options and under the Directories tab, change the output directory to a folder that exists and try again.

PretoriaCoder
  • 591
  • 6
  • 13
0
  1. Try to open the windows task manager
  2. go to process if you can not find your app in here
  3. then go to details tab you will find it.

I had the same problem and then I found it on details tab.

Dharman
  • 21,838
  • 18
  • 57
  • 107
Andy V
  • 1
0

1/29/2020: During the past week, I experienced this: Load a project in Delphi 7 on a Win 10 machine, compile it (successfully), run the project from inside of D7 (successful), recompile the project and get a "cannot create ....project1.exe". Upon reboot, can successfully compile and execute, but the second compile fails as the above. I found that Dell Support Assist had an update 8 days ago (about the time this started), so I uninstalled it. After that, no problems with D7.

Keith
  • 1
0

A solution that has worked for me, change project options -> Linking and leave it like that, then delete the executable manually and solved.Project options -> linking

-1

I seem to have fixed it by setting the compatibility mode to XP SP3. This also fixed another annoyance which made Alt-P not open bring up the Project menu.

EDIT: I didn't have to re-enable my Application Experience. Still dead where it should be :)

Right-click on your Delphi short-cut, Properties, then choose the Compatibility tab. Choose Run the program in compatibility mode for: Windows XP (Service pack 3).

(I also checked the Run this program as an administrator box, but you may choose not to do that.)

(This is for Delphi 7, as per the OP's question, not for XE7, although it may work for that too.)

Compatibility settings

Reversed Engineer
  • 967
  • 10
  • 23