11

Just now I found that static libraries in *nix systems, in other words *.a libraries are nothing but archives of relocatables(*.o files) in ar fromat.

  1. What about static libraries(*.lib files) in windows? Which format are they in?

  2. I found an article (archived copy 1, archived copy 2) which explains *.lib file structure. But Where can I find "Official" specifications of *.lib file structure/format?

  3. Other than ar.exe of mingw is there any tool from Microsoft which extracts relocatable objects of *.lib & *.a files?

EDIT:

I wonder why I'm unable to get to this question. If there are no official specifications. Then how does the compiler ('linker' to be more correct) writers work with *.LIB files?

Anton Samsonov
  • 1,380
  • 17
  • 34
claws
  • 52,236
  • 58
  • 146
  • 195

2 Answers2

11

I found that *.LIB file uses the ar file format.

Official Specifications: Section 7. "Archive (Library) File Format" of Microsoft Portable Executable and Common Object File Format Specification describes this format.

Steve Pitchers
  • 7,088
  • 5
  • 41
  • 41
claws
  • 52,236
  • 58
  • 146
  • 195
  • The linked specification is a docx file, here is a webpage with the current specification: https://learn.microsoft.com/en-us/windows/desktop/Debug/pe-format#archive-library-file-format – Lekensteyn Dec 16 '18 at 20:17
2

mingw's ar works just fine on *.lib files - even ones created under VisualStudio.

We've actually used it in the past to pull out parts of a library we needed when it contained some other stuff we couldn't link with (due to conflicts with other libraries). Kinda hacky, but it works.

T.E.D.
  • 44,016
  • 10
  • 73
  • 134
  • 1
    Thats a useful piece of info. But does this mean that *.lib files are also in `ar` format? May be, mingw's ar.exe is abstracting the underlying format and behaving in the same way. – claws Mar 03 '10 at 14:05
  • Don't really know. I was mostly answering #3 I guess. – T.E.D. Mar 04 '10 at 13:50