Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

.a is an archive of code: compiled but not linked. You would link statically with it during your program's final link step.

.lib can be either the same as .a, or a magical so-called "import library": a thin placeholder which causes you to require a .dll at runtime.

I'm compiling the QT framework with a .a OpenSSL library, but somehow my final executable produced by QT is still requiring an external OpenSSL dll in order to run. Do you have any idea how this could be the case given that I'm using a .a library? – Nantucket Feb 26, 2010 at 0:09 How were the contents of the OpenSSL .a compiled? How are you linking your final executable? – crazyscot Feb 26, 2010 at 8:52 I am not sure about "require a .dll at runtime". You will not need .dll if your project is using .lib static libraries (unless there are .dll dependencies which you haven't identified correctly). – ha9u63a7 Aug 26, 2014 at 7:10 Huh? Even import libraries are ar files, it's merely their contents that differs. Another difference are the paths that may occur for contained "members". – 0xC0000022L Dec 15, 2022 at 22:33

On Unix systems you have the .a files. These are simple archives of object files ( .o ).

On Windows, there are .lib files, which are quite the same thing, but for Windows instead of Unix.

An additional subtlety is that in order to link some code against a DLL (on Windows), you have to link against a .lib file which contains simple wrappers which invoke the DLL. On Unix system, traditionally, there is no need for such wrappers (the linker is smart enough to generate them on the fly).

Thank you for this answer, found out I was trying to compile with a Windows flag on somewhere! :) – SSH This Dec 4, 2012 at 21:56 I have an example here without the need of a .lib on a shared (.dll) library in windows: github.com/ConsoleTVs/C_Static_Shared_Libraries – Erik Campobadal Nov 11, 2018 at 21:28

Something I don't see mentioned here yet is the surprising fact that, at least some of the time, .a files and .lib files are actually the same binary format . Although I couldn't find anything saying as much on the mingw website, I noticed that when trying to get MS Visual C++'s 64-bit compiler cl.exe to link in a .dll file produced using the mingw-w64 g++ compiler, it happily accepted the command line

cl /EHsc /Ipath\to\include gmp_test.cpp path\to\lib\libgmp.dll.a

and the resulting .exe file ran correctly as soon as I put a copy of the corresponding .dll file in the current directory. (It did mumble the warning "Command line warning D9024 : unrecognized source file type 'path\to\lib\gmp-6.0.0\lib\libgmp.dll.a', object file assumed".)

Further evidence is that the Linux file command reported "current ar archive" for several files of each extension (.lib or .a) I tried.

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid …

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.