On Windows, files with the .lib
extension can sometimes be confusing because they don't all serve the same purpose - some are static libraries that bundle compiled object files, while others are import libraries that act as lightweight references to corresponding DLLs. When troubleshooting linker errors, checking dependencies, or simply understanding how a library is packaged, it's useful to know which kind of library you have. This tutorial demonstrates how to check if library is static or import on Windows.
The Visual Studio includes the lib
tool, which can list and manage library contents. Run it from the Developer Command Prompt for Visual Studio.
The lib
command's /LIST
option lets you examine the contents of a library. Since static libraries are collections of .obj
files, the presence of any .obj
entries indicates that the library is static. If no .obj
files are found, the library is an import library. For example, the following command checks if the zlib.lib
library is static or import:
lib /LIST zlib.lib | findstr /i ".obj" >nul && echo True || echo False
If the command prints True
, the library is a static library containing object files; if it prints False
, the library is an import library that relies on a DLL.
Explanation of the command parts:
lib /LIST zlib.lib
- lists all the contents of the provided library.findstr /i ".obj" >nul
- searches the output for any lines containing.obj
(case-insensitive) and hides the actual output.echo True || echo False
- printsTrue
if.obj
files were found, orFalse
if none were found.
Leave a Comment
Cancel reply