MSVC build errors > LNK1168
LNK1168: cannot open file for writing
fatal error LNK1168: cannot open C:\Projects\App\x64\Debug\App.exe for writing
The linker could not overwrite the program it builds, because another process holds the file open.
Causes and fixes
- The program is still running. Close it, or stop debugging. A console program that waits for a key, or a process that hangs after its window closed, keeps the file locked: end it in Task Manager.
- Another tool holds the file. An antivirus scanning the new file, a profiler, or a process that loaded the DLL can lock it for a moment: build again, or close that tool.
- The file is read-only. Clear the read-only attribute of the output file or folder.
Fix LNK1168 with CppPilot
CppPilot reads the error, your code, and the project settings Visual Studio evaluates for the active configuration, then explains which of these causes applies. Choose Fix and the AI corrects it; CppPilot rebuilds the project and checks that the error is gone. Every change appears in Visual Studio for your approval.
Let the AI fix it in Visual Studio
CppPilot is a free extension that explains and fixes MSVC build errors with Codex, Claude, or CppPilot Cloud.
Related errors: LNK1104. See all guides.