I am trying to understand creation and use of static libraries and shared libraries in Linux using Program Library HOWTO. There are two statements in the link that I am confused about:

  1. Static libraries permit users to link to programs without having to recompile its code, saving recompilation time.
  1. Static libraries are often useful for developers if they wish to permit programmers to link to their library, but don't want to give the library source code.

Regarding 1: The static libraries end up as part of the executable while shared libraries stay separate and are only loaded when the executable starts execution. However, don't both these libraries have the advantage of not having to be recompiled when a new application wants to use them - assuming there are no changes to the library itself? If that's true why does the statement give the impression that it is an advantage of static libraries over shared libraries?

Regarding 2: Once again, doesn't this apply to shared libraries as well? The shared libraries also use object files, even though they are generated as PIC in a format specific to the architecture. So, is source code being shared in this case?

2 Answers 2


I think the guide is supposed to be understood in the order it’s presented in, without assuming external knowledge about libraries. Thus in chapter 2, “Static Libraries”, comparisons don’t involve shared libraries, which haven’t been introduced yet.

So both excerpts are comparisons to source code only: compared to providing source code, building static libraries allows compilation objects to be re-used without being recompiled, and without even having to provide their source code.


The excerpts are unclear.

Static libraries become part of the executable, and are unavailable outside that executable. See man ld. They're treated just like external functions. Statically linked executables are bigger than dynamically linked executables, but they are complete. self-sufficient.

When using dynamically linked libraries, the program supplies the library name. required version, etc. See man elf readelf When the program is loaded by ld.so (see man ld.so), the dynamically linked library is mapped into the task's memory (see man mmap), and an indirect call table is set up so the program can access the library. Dynamically linked libraries let the system share 1 in-RAM copy of the library among ALL the tasks. Dynamically library use makes executables smaller, and delegates keeping the library up-to-date to the Sysadmin. However, resolving libraries at execution time can fail, if the required libraries and versions are not available. They are neither complete nor self-sufficient.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .