Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

As far as I understand they are libraries, but what is the difference between the two?

share|improve this question
add comment

2 Answers

up vote 17 down vote accepted

A .a file is a static library, while a .so file is a shared object (dynamic) library similar to a DLL on Windows. There's some detailed information about the differences between the two on this page.

share|improve this answer
8  
.a can only be included as part of a program during compiling. .so's can be "imported" while a program loads. –  ultrasawblade May 14 '11 at 23:39
add comment

As a follow on, a .a file is an "ar" archive. Not unlike a tar archive, it stores .o or object files, allowing them to be pulled out of the archive, and linked into a program, among other things. You could use ar to store other files if you wanted.

You can get a listing of the members of an ar file with the -t parameter, for instance:

ar -t /usr/lib/libc.a

A .so file is a "shared object" file, and has a lot more information available to the linker so that members can be linked in to a loading program as rapidly as possible.

For instance, try:

objdump -T /lib/libc-2.11.1.so

(or whatever version of libc.so you have in your /lib directory.) Note that a .so file could also just contain a linker script directing it to find the file elsewhere, or use something else.

Interestingly, a .so file can also be a full fledged program. For instance, trying running /lib/libc.so.6. (Sadly, this last part doesn't seem to work on more modern systems. Not that it's a great loss.)

share|improve this answer
    
Typo. you mean to write ar -t /usr/lib/libc.a. Actually the - doesn't seem to be necessary in this case. Also /lib/libc.so.6. just prints some output. I don't know if I would call it a full fledged program. –  Faheem Mitha May 15 '11 at 8:09
    
Thanks for the typo pointer. –  Hack Saw May 16 '11 at 16:04
1  
It's a full fledged program in the sense that it has a main symbol for exec to find. –  Hack Saw May 16 '11 at 16:05
1  
You can also run ldd on .so's, and it will show you what other libraries it uses. Static will return with a message saying it's not a dynamic library. –  Marcin May 17 '11 at 1:06
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.