View Object Files of Static Library on Windows

View Object Files of Static Library on Windows

When developing software on Windows with Visual Studio, you'll often see static libraries - files ending in .lib. These libraries are essentially bundles of precompiled object files (.obj) combined into a single archive. Sometimes, you might need to check which object files were included, especially if you're troubleshooting linker errors, or simply inspecting the contents of a third-party library. This tutorial shows how to view object files of static library on Windows.

Visual Studio provides a command called lib, which can be used to create, manage, and explore static libraries. It's available in the Developer Command Prompt that ships with Visual Studio.

To list all object files stored in a static library, we can use /LIST option. For example, the following command checks zlibstatic.lib static library:

lib /LIST zlibstatic.lib

This command will display the collection of object files packed into the library. Example:

adler32.obj
compress.obj
crc32.obj
deflate.obj
gzclose.obj
gzlib.obj
gzread.obj
gzwrite.obj
inflate.obj
infback.obj
inftrees.obj
inffast.obj
trees.obj
uncompr.obj
zutil.obj

It's important to note that on Windows, there are two types of .lib files:

  • Static libraries (like the one above), which directly contain compiled code.
  • Import libraries, which are paired with .dll files. They provide references that tell the linker how to connect the program to the DLL at runtime. In this case, the lib /LIST command is not applicable, since there are no object files to enumerate.

Leave a Comment

Cancel reply

Your email address will not be published.