2

We are porting our linux development to windows.

To create a static library, we still use ar under windows (Msys2) to create a libXXX.a file. The windows way is actually to create a .lib file using some windows tool. But the libXXX.a file seems to work fine on our msys2 tool chain. But linking against this file is VERY slow. So what is the difference between a .a and a .lib file? Would creating a .lib file speed up the linking?

gexicide
  • 38,535
  • 21
  • 92
  • 152
  • The `a` in `libxxx.a` stands for *Archive*. It is simply an uncompressed archive of object files. While I don't know anything about `.lib` files as used by Visual Studio, I would guess that as its base they are also just an archive of object files. Knowing Windows and Visual Studio, there is probably more to it than that, but the heart of it could still be an archive of object files. – Some programmer dude Jul 15 '16 at 12:07
  • @JoachimPileborg: I know that `ar` creates an archive. The question is, what is a `.lib` file and how does it relate to an archive. – gexicide Jul 15 '16 at 12:14
  • [Related (if not duplicate) question](http://stackoverflow.com/questions/2371531/which-format-does-static-library-lib-files-use-where-can-i-find-official). – Some programmer dude Jul 15 '16 at 12:24
  • Very different file formats, .a is ELF and .lib is COFF. Speed is always a vague complaint, maybe you got too used to the MSVC linker's /incremental option. Very easy to get used to. Or you just link too many static libraries instead of shared libraries (DLLs), very common in open source. – Hans Passant Jul 15 '16 at 12:48
  • @HansPassant: I am used to linux development. On linux, the link process is currently 8 times faster than on windows. Also, the `a` file on my msys2/mingw platform also contains `COFF` and the compiler happily accepts it, so this cannot be the only difference. – gexicide Jul 15 '16 at 15:19

1 Answers1

1

Both .a and .lib are archives that contain a bunch of object files. The difference is that in the former case they are ELF binaries and in the latter they are COFF files (MS COFF). And probably your toolchain needs some extra efforts to link against non-native object format.

P.S. .lib files also often may contain stubs for creating dynamic imports instead of COFF objects. And it also may affect build time for the same reason (non-native data format).

P.P.S Obviously to speed up linking process all inputs must have the same format, that is native for linker.

Sergio
  • 8,099
  • 2
  • 26
  • 52
  • 1
    The object files in my `.a` are COFF files. I am on windows and using the mingw toolchain which produces COFF. `ar` doesn't care what you want to archive. It will happily archive COFF files. – gexicide Jul 15 '16 at 13:55