How do I fix lnk1168 error?

  • Remove From My Forums

Show

    • Question

    • When I first compile and link a solution, everything works fine. However, often (about 60 - 70% of the time), subsequent link operations fail unable to open the .exe file for writing. I've checked the obvious things such as the application still running and even trying to delete the existing file via explorer fails saying the file is in use.

      If I wait long enough - sometimes up to 5 minutes - then all works well again. I haven't worked out when this happens. It usually happens if I encounter an unhandled exception during a test run, but sometimes I get this even when the test run was clean.

      Any ideas?

    Answers

    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:

    1. The app is not running and it's not shown in the Task Manager.
    2. Going into the project directory and trying to remove it with hands comes with success but the file APPEARS AGAIN FROM NOWHERE.
    3. The system restore is disabled.
    4. I also tried to take the ownership of the whole damn drive.
    5. Every time I delete the file it recreates itself again but sometimes it stops doing that.
    6. If I delete the file (and it recreates after that), and then I start sysinternals procmon then the file disappears.
    7. If I start procmon before - then the file keeps appearing after delete like always.

    OS: W7 SP1 64-bit, with latest updates

    Any ideas, please?

    How do I fix lnk1168 error?

    Amal K

    3,9292 gold badges18 silver badges40 bronze badges

    asked Aug 25, 2012 at 17:25

    1

    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.

    answered Jul 6, 2013 at 6:53

    CodeMedCodeMed

    9,60369 gold badges204 silver badges351 bronze badges

    7

    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!

    answered Sep 17, 2019 at 16:20

    How do I fix lnk1168 error?

    Amal KAmal K

    3,9292 gold badges18 silver badges40 bronze badges

    1

    Restarting Visual Studio solved the problem for me.

    answered Jan 7, 2017 at 18:15

    Aleksei MialkinAleksei Mialkin

    2,0121 gold badge24 silver badges25 bronze badges

    1

    In my case, cleaning and rebuilding the project resolved the problem.

    Uli Köhler

    12.7k15 gold badges65 silver badges116 bronze badges

    answered Mar 2, 2014 at 15:35

    Hau LeHau Le

    1211 silver badge5 bronze badges

    If the above solutions didn't work, you can try this which worked for me.

    Open an elevated command prompt (cmd -> Run as administrator), then write following command and hit enter:

    wmic process where name='YOUR_PROCESS_NAME.exe' delete
    

    If you see a message: Instance deletion successful., then you will be again able to build and run project from VS.

    e.g. in OP's case, the command will be:

    wmic process where name='console.exe' delete
    

    answered Aug 3, 2021 at 9:06

    UkFLSUIUkFLSUI

    5,3816 gold badges33 silver badges47 bronze badges

    well, I actually just saved and closed the project and restarted VS Express 2013 in windows 8 and that sorted my problem.

    answered Apr 8, 2015 at 17:50

    2

    The Reason is that your previous build is still running in the background. I solve this problem by following these steps:

    • Open Task Manager
    • Goto Details Tab
    • Find Your Application
    • End Task it by right clicking on it
    • Done!

    answered Aug 4, 2020 at 12:48

    How do I fix lnk1168 error?

    back2Lobbyback2Lobby

    4736 silver badges11 bronze badges

    This solved same problem I also came across very well

    1. Close the app if it is still running on the taskbar,
    2. Open cmd (command prompt) and run the following
    taskkill /F /IM ApplicationName.exe
    
    1. Rebuild your project!! error solved!

    answered Sep 25 at 1:11

    niosnios

    411 silver badge7 bronze badges

    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.

    answered Oct 9, 2015 at 2:44

    Laurie StearnLaurie Stearn

    9431 gold badge12 silver badges32 bronze badges

    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! :)

    answered Oct 4, 2019 at 5:25

    How do I fix lnk1168 error?

    tw1tch01tw1tch01

    491 silver badge4 bronze badges

    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

    answered Aug 14, 2020 at 14:32

    If none of the above suggested work for you, which was the case for me, just change the project name. It creates a new exe in the new project name. Later when you restart, you can change it back to your original project name.

    answered Aug 22, 2021 at 9:43

    RathnavelRathnavel

    751 silver badge12 bronze badges

    I know this is an old thread but I was stumbling in the same problem also. Finding it in task manager is tricky, and I started to grow tired of having to restart my PC every time this happened.

    A solution would be to download Process Explorer and there you can search for running tasks. In my case I was having the following error:

    1>LINK : fatal error LNK1168: cannot open C:Out\Build\VS12_app\Debug\platform_test.exe for writing [C:Build\VS12_app\platform_test.vcxproj]

    I searched for C:Out\Build\VS12_app\Debug\platform_test.exe in Process Explorer, killed it and I was able to compile.

    answered Sep 15 at 11:15

    How do I fix lnk1168 error?

    Ra'wRa'w

    1031 silver badge10 bronze badges

    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.

    answered Sep 12, 2013 at 23:54

    JasonJason

    1471 gold badge2 silver badges11 bronze badges

    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.

    answered Jan 6, 2014 at 15:07

    0