28

I am trying to compile a 3rd party library( on linux) and see that it is generating libsomething.a files I have my other libraries which are .so file

But it appears that even .a is shared library and can be used just like a .so lib

So is there any difference between the two ? or they are just same with different naming convention.

rajshenoy
  • 501
  • 1
  • 7
  • 16
  • 2
    What makes you say they can be used in the same way? – Carl Norum Sep 06 '12 at 05:34
  • @CarlNorum because it's possible to link against both type - just the result will be different. –  Sep 06 '12 at 05:35
  • @H2CO3, that's a pretty weak definition of 'can be used just like', but I'll buy it, I guess... – Carl Norum Sep 06 '12 at 05:36
  • 1
    @Carl Norum, if i knew the exact difference i would have not asked the Question. I know that .so is shared library but found somewhere that .a also is shared library but i dont know if it is static library or shared library – rajshenoy Sep 06 '12 at 07:03
  • @CarlNorum Right - indeed, "the same way" is not really the same way. –  Aug 19 '13 at 19:33

3 Answers3

37

A .a file is a static library, while a .so file is a shared object dynamic library similar to a DLL on Windows.

A .a can be included as part of a program during the compilation. A .so can be imported, while a program loads.

Løiten
  • 3,185
  • 4
  • 24
  • 36
thar45
  • 3,518
  • 4
  • 31
  • 48
21

When you link against the *.a, the code from the library is included in the executable itself and the executable can be run without requiring the *.a file to be present. When you link against the *.so, that is not the case and the *.so file must be present at runtime.

William Pursell
  • 204,365
  • 48
  • 270
  • 300
20

But it appears that even .a is shared library

Nope, it's a static library.

and can be used just like a .so lib

If you mean linking to it, then yes. But you can't dlopen() an .a file which you could do with an .so file.

You can always ask our old friend Uncle G to answer your questions.

  • Thanks. This is where i got confused. My issue was not about linking them. both can be linked . but i wanted to know if .a can be linked dynamically or statically only. its clear now – rajshenoy Sep 06 '12 at 07:20
  • 9
    The link to "Uncle G" is broken. – splungebob May 11 '16 at 17:32