Introduction
A Windows .lib is a library for the linker. Microsoft’s tools in
Visual Studio make it, as do
LLVM’s tools. It is an ar archive whose members are
COFF object files (a static library) or
short import objects (an import library,
which names the functions a DLL exports).
Structure
0signature!<arch>\n8 bytes8first linker member/: symbol offsets, big-endian60 bytes + size…second linker member/: sorted symbol index, little-endian60 bytes + size…longnames member//, if any60 bytes + size…members: COFF object files or short import objectsvaries
The two linker members index the public symbols. Names of more than 15 characters are stored in the longnames member.
The member header
Each member starts on an even offset, with this 60-byte header. Every field is ASCII, padded on the right with spaces:
| Offset | Size | Field | Meaning |
|---|---|---|---|
| 0 | 16 | Name | The name followed by /; the special names / and //; or / and a decimal offset into the longnames member |
| 16 | 12 | Date | The time the member was made, in decimal seconds since 1970; often 0 or -1 in a reproducible build |
| 28 | 6 | User ID | Blank or 0 on Windows |
| 34 | 6 | Group ID | Blank or 0 on Windows |
| 40 | 8 | Mode | The file mode, in octal |
| 48 | 10 | Size | The size of the member’s data in bytes, in decimal, not counting this header |
| 58 | 2 | End | Always ` and a newline: 60 0A |
A member’s data is followed by a newline byte if its size is odd, so that the next header starts on an even offset.
Variants
- Windows COFF library – a Windows static or import library in the ar archive format
- Short import object – one member of an import library: a header and two strings
- OMF library – a library of OMF object modules from 16-bit compilers
Links
Software
- Visual Studio – Microsoft’s development environment, with
libanddumpbin(Windows) - LLVM – compiler toolkit with
llvm-libandllvm-ar(Windows, macOS, Linux) - 7-Zip – free archiver that can list and extract the members (Windows)
Reference
- PE Format – Microsoft’s specification, with sections on the archive and import library formats