differences between static and dynamic libraries (C && LINUX)

Manuel Bedoya
3 min readMay 3, 2021

--

What are the differences between static and dynamic libraries

Why using libraries in general ?

The libraries is awesome when you want use a function that you use many times and this function never change in this cases the libraries is the best option , also the some advavantages have the libraries are the speed, Lower cost in development, etc…

How to create libraries ?

I have a post where explain all about the static libraries you can see it with the following link:

In this post we going to talk about the dynamic libraries , to create a library in C then you have the functions executables of the following way :

(-c) By default, the object file name for a source file is
made by replacing the suffix .c, .i, .s, etc., with .o.

(*.c) is take all files tha ends in .c

(-fPIC) is important flag ensures that the code is position-independent.

The last step to save and finsh created your dynamic librarie is typing the following command:

(*.o) Take all the files to end whith .o

(-shared) Produce a shared object which can then be linked with other
objects to form an executable

(-o) To give a name a file output

How to use Dynamics libraries?

We use the function _strlen to use it only compile the file main with the dynamic librarie

(-L) looks in the directory for library files

What are the advantages and drawbacks of each of them

static libraries

Adventages:

  • You do not need to provide the appropriate libraries when publishing the program.
  • Fast load

Drawbacks

  • The library is packaged in the application, resulting in a large library.
  • The library has changed and the program needs to be recompiled.

Dynamic libraries

Adventages:

  • programs written in different programming languages can call the same DLL function just according to the function calling convention

Drawbacks

  • Uncompatible/Unsoported with some systems.

--

--

Manuel Bedoya
Manuel Bedoya

No responses yet