Using a static library means only one object file need be pulled in during the linking phase. This contrasts having the compiler pull in multiple object files (one for each function etc) during linking. The benefit of using a static library is that?the functions and other symbols loaded into it are indexed .
Steps to create a static library?Let us create and use a Static Library in UNIX or UNIX like OS.
1.?Create a C file that contains functions in your library.
We have created only one file for simplicity. We can also create multiple files in a library.
2.?Create a header file for the library that contains all the prototypes .
3.?Compile library files.
4.?Create static library. This step is to bundle multiple object files in one static library (see?ar?for details). The output of this step is static library.
- For a static library, the actual code is extracted from the library by the linker and used to build the final executable at the point you compile/build your application.
- Each process gets its own copy of the code and data. Where as in case of dynamic libraries it is only code shared, data is specific to each process. For static libraries memory footprints are larger. For example, if all the window system tools were statically linked, several tens of megabytes of RAM would be wasted for a typical user, and the user would be slowed down by a lot of paging.
- Since library code is connected at compile time, the final executable has no dependencies on the library at run time i.e. no additional run-time loading costs, it means that you don’t need to carry along a copy of the library that is being used and you have everything under your control and there is no dependency.
- In static libraries, once everything is bundled into your application, you don’t have to worry that the client will have the right library (and version) available on their system.
- One drawback of static libraries is, for any change(up-gradation) in the static libraries, you have to recompile the main program every time.
- One major advantage of static libraries being preferred even now “is speed”. There will be no dynamic querying of symbols in static libraries. Many production line software use static libraries even today.