Programmers’ theoretical minimum: how create static or dynamic library
Create a static or dynamic library isn’t hard indeed.
It’s enough to compile your code without a main routine and process the resulting objects (.o) files with the correct utility ar for static libraries or ld for dynamic libraries:
#####square.h
#####square.c
As first step is necessary to product the objects files passing -c to gcc compiler:
####Creating the static library Static libraries are known as archives and they are created and updated using the ar (archive) utility.
Convention dictates that static library’s name starts with lib and has an .a extension.
####Creating the shared library using ld A dynamically linked library is created by the link editor ld. The conventional file extension for a dynamic library is .so meaning shared object, because every program linked against this library shares the same one copy, in contrast to static linking, in which everyone is (wastefully) given their own copy of the contents of the library.
####Creating the shared library using gcc A dynamic library can also be created using gcc and passing the -shared option, like below:
##Further Information
Creating a shared and static library with the gnu compiler [gcc]