MSVC: fatal error LNK1104: cannot open file 'foo.lib' (or 'app.exe' while it is running)
The Visual C++ linker could not open an input library or the output file — the path is wrong, the library is missing, or the .exe is still running or locked.
LNK1104: cannot open filefatal error LNK1104cannot open file 'kernel32.lib'LNK1104: cannot open file '.exe'LNK1181: cannot open input file Meaning
Two different situations share this code: an input (.lib, .obj) that cannot be found in the library search paths, or an output (.exe, .dll, .pdb) that cannot be written because a debugger, a running instance, an antivirus scan or a sync tool holds it open. The file name in the message tells which one it is.
Common causes
- Library directory not listed in Linker → General → Additional Library Directories
- Library name or
.libextension misspelled, or only the DLL is present - Mixing 32-bit and 64-bit library folders
- Output
.exestill running or locked by antivirus / OneDrive - Path contains an unexpanded macro or invalid characters
⚡ Quick fix
- Add the folder under Additional Library Directories and the file name under Additional Dependencies
- Close the running program (Task Manager) and rebuild
- Use matching platform folders (x64 vs Win32) for the library and the project
Detailed fix by platform
Visual Studio
- Project Properties → Linker → General → Additional Library Directories; Linker → Input → Additional Dependencies (
foo.lib) - Make sure Configuration (Debug/Release) and Platform (x64/Win32) match the library build
Windows
- Find a locked output:
tasklist | findstr app.exethentaskkill /IM app.exe /F
Code examples
Library path in CMake
find_library(FOO_LIB NAMES foo PATHS "C:/libs/foo/lib/x64")
if(NOT FOO_LIB)
message(FATAL_ERROR "foo.lib not found")
endif()
target_link_libraries(app PRIVATE ${FOO_LIB})How to diagnose
- File — Library to read or output to write?
- Path — Is the folder on the library search path?
- Platform — Do x64/Win32 and Debug/Release match?
🔧 Still not fixed?
Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:
Similar errors
Most viewed in C/C++
- terminate called after throwing an instance of C++: terminate called after throwing an instance of 'std::out_of_range' — what(): vector::_M_range_check
- double free or corruption C/C++: free(): double free detected / double free or corruption (out) — Aborted (core dumped)
- expected ';' before C/C++: error: expected ';' before 'x' — missing semicolon
Other ways to find it
Where this error sits
Origin: Application & API. Errors that are often confused with or caused by this one (click to open):
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
💬 What worked for others
No tips yet — did something else fix this for you?
Share what worked for you
Tips are checked by an editor before they appear. Links are removed.
Report a correction or suggest an improvement
Last updated 15 Oct 2026