Developing with libraries
Most applications make use of shared libraries, which saves system memory and disk space, as they are shared between different applications. Modularizing code into libraries also allows for easier versioning and code management, as well as independent updates from the applications that use them. This recipe will explain how to work with both static and shared libraries.
Getting ready
By convention, library files start with the lib
prefix. All libraries need to be explicitly passed to the linker so that they are used, except libc
which will be automatically linked. There are basically two library types:
- Static libraries (
.a
): When the object code is linked and becomes part of the application. - Dynamic libraries (
.so
): These are linked at compile time but not included in the application, so they need to be available at runtime. Multiple applications can share a dynamic library so they need less disk space.
Libraries are typically placed in the following standard root filesystem...