Suddenly, my Visual Studio Express 2010 C++ stopped rebuilding my project. When I first hit F7 the project builds and runs fine (heck, it's a hello world example).
Then I make some changes and hit F7 again, then I get:
1>LINK : fatal error LNK1168: cannot open C:\Users\username\Documents\Visual Studio 2010\Projects\console\Debug\console.exe for writing**<br><br>
Now the funny thing comes:
OS: W7 SP1 64-bit, with latest updates
Any ideas, please?
This question is related to
c++
windows
visual-c++
The Reason is that your previous build is still running in the background. I solve this problem by following these steps:
In my case, cleaning and rebuilding the project resolved the problem.
well, I actually just saved and closed the project and restarted VS Express 2013 in windows 8 and that sorted my problem.
I've encountered this problem when the build is abruptly closed before it is loaded. No process would show up in the Task Manager, but if you navigate to the executable generated in the project folder and try to delete it, Windows claims that the application is in use. (If not, just delete the file and rebuild, which generates a new executable) In Windows(Visual Studio 2019), the file is located in this directory by default:
%USERPROFILE%\source\repos\ProjectFolderName\Debug
To end the allegedly running process, open the command prompt and type in the following command:
taskkill /F /IM ApplicationName.exe
This forces any running instance to be terminated. Rebuild and execute!
FINALLY THE BEST WAY WORKED PERFECTLY FOR ME
None of the solutions in this page worked for me EXCEPT THE FOLLOWING
Below the comment sections of the second answer, try the following :
Adding to my above comment, Task Manager does not display the filename.exe process but Resource Monitor does, so I'm able to kill it from there which solves the issue without having to reboot. – A__ Jun 19 '19 at 21:23
I also had this same issue. My console window was no longer open, but I was able to see my application running by going to processes within task manager. The process name was the name of my application. Once I ended the process I was able to build and compile my code with no issues.
I know this is an old question but thought I'd share how I resolved the issue.
If you're using Visual Studio and this error occurs, you can try to attach to process (CTRL+ALT+P) and find the "(program).exe" process. When you try to attach to it, an error will display stating that it failed to attach which removes the process from "running" (even though it's not...) You'll also be able to delete the (program).exe from your Debug folder.
Hope this helps someone! :)
The problem is probably that you forgot to close the program and that you instead have the program running in the background.
Find the console window where the exe file program is running, and close it by clicking the X in the upper right corner. Then try to recompile the program. In my case this solved the problem.
I know this posting is old, but I am answering for the other people like me who find this through the search engines.
Start your program as an administrator. The program can't rewrite your files cause your files are in a protected location on your hard drive.
This can also be a problem from the improper use of functions like FindNextFile when a FindClose is never executed. The process of the built file is terminated, and the build itself can be deleted, but LNK1168 will prevent a rebuild because of the open handle. This can create a handle leak in Explorer which can be addressed by terminating and restarting Explorer, but in many cases an immediate reboot is necessary.
Restarting Visual Studio solved the problem for me.
Source: Stackoverflow.com