Are there files libfoo.a and foo.lib?

Some build scripts (for example, one in numpy) simply do the following so that the gcc-compiled library archive works with the Visual Studio linker:

copy libfoo.a foo.lib 

Surprisingly, this works. Does anyone know why?

+4
source share
2 answers

Depending on several factors, it may or may not work - and for several reasons. I suppose you mean full compatibility with reversibles.

  • For imbibs, which are used to associate DLLs with executable files, the answer is no .

    I once tried to associate MSVC ++ implib with a dll created by gcc. If the formats were compatible, this would work when I renamed the libfoo.a library. To get around this, there is a utility called reimp that can create a suitable gcc implib from a DLL. To reverse the process, Microsoft's lib tool can create a static implib from a .def file, which gcc can create using a DLL if the correct flags are assigned to it. [Search "reimp" on the mingw website for more information]
  • C ++ - compiled object files are also incompatible due to Name Mangling .

    Different C ++ compilers change the names of variables and objects in different ways, resulting in "code [object] ... which usually doesn't bind"
  • For a static library compiled as plain old C? <i> Yes

    I need a little more information about what type of project you are, but if it is C and `copy libfoo.a foo.lib` works, it could be. Try to check if this works the other way around with Mingw or Dev-C ++. Edit : Actually, this will only work if the library is compiled with gcc on the Windows platform (and it works both ways!). the only exceptions to this AFAIK are cross-compiled libraries - MSVC refuses to take them with at least the one provided by Ubuntu β€œi586-mingw32msvc-ar”.

Another alternative explanation is that the MSVC linker is compatible with the .a format for historical reasons. IIRC, it has been since UNIX. Again, although I could see that this only works for pure C, not C ++.
EDIT : Actually, it's the other way around. The Windows version of the GCC toolkit creates static libraries compatible with the Microsoft COFF format.

+3
source

While I do not know any details for the lib format, I can give some information about the lib * .a format. This is just an archive of * .o object files and can be managed using the ar program (part of binutils ).

 prompt>ar t /usr/lib64/libc.a | head init-first.o libc-start.o sysdep.o version.o check_fds.o libc-tls.o elf-init.o dso_handle.o errno.o errno-loc.o prompt>ar t /usr/lib64/libc.a | wc 1447 1447 16904 prompt> 

I assume that * .lib is also an archive of object files with an identical or compatible content index.

+1
source

All Articles