LNK1104 C/C++ Origin: Application & API Last updated 15 Oct 2026

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.

Exact message you may see LNK1104: cannot open filefatal error LNK1104cannot open file 'kernel32.lib'LNK1104: cannot open file '.exe'LNK1181: cannot open input file
Seen on: C/C++ MSVC Windows

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 .lib extension misspelled, or only the DLL is present
  • Mixing 32-bit and 64-bit library folders
  • Output .exe still running or locked by antivirus / OneDrive
  • Path contains an unexpanded macro or invalid characters

⚡ Quick fix

  1. Add the folder under Additional Library Directories and the file name under Additional Dependencies
  2. Close the running program (Task Manager) and rebuild
  3. Use matching platform folders (x64 vs Win32) for the library and the project

Detailed fix by platform

Visual Studio

  1. Project Properties → Linker → General → Additional Library Directories; Linker → Input → Additional Dependencies (foo.lib)
  2. Make sure Configuration (Debug/Release) and Platform (x64/Win32) match the library build

Windows

  1. Find a locked output: tasklist | findstr app.exe then taskkill /IM app.exe /F

Code examples

Library path in CMake

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

  1. File — Library to read or output to write?
  2. Path — Is the folder on the library search path?
  3. 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:

Where this error sits

Origin: Application & API. Errors that are often confused with or caused by this one (click to open):

C2065 — MSVC: error C2065: 'x': undeclared identifier (C/C++)C2065C4996 — MSVC: error C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead (C/C++)C4996multiple definition of — C/C++: multiple definition of `x'; first defined here — ld returned 1 exit status (C/C++)multiple definition ofundefined reference to — C/C++: undefined reference to `function' — collect2: error: ld returned 1 exit status (C/C++)undefined reference toundefined reference to main — C/C++: undefined reference to `main' — (.text+0x20) in crt1.o (C/C++)undefined reference t…undefined reference to pthread_create — C/C++: undefined reference to `pthread_create' — missing -pthread (also `dlopen`, `clock_gettime`) (C/C++)undefined reference t…undefined reference to vtable — C++: undefined reference to `vtable for X' — virtual function not defined (C/C++)undefined reference t…LNK1104

Explore the map of this error Full error map →

🧠 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.