Differences between static and dynamic libraries

Why use libraries?

How do they work? And What are the differences between static and dynamic libraries?

Static Library

Dynamic library

How to create them(Linux)?

Static Library:

gcc -Wall -pedantic -Werror -Wextra -c *.car -rc libholbertonschool.a *.o
ar -t libholbertonschool.a
/* Run */
ranlib libholbertonschool.a
gcc main.c -L. -lholbertonschool -o alpha
./alpha
ranlib libholbertonschool.a

Dynamic Library:

gcc -Wall -fPIC -c *.c
gcc -shared -o liball.so *.o

How to use them(Linux)?

gcc main.c -L. -lholbertonschool -o alpha

Also before compile is important to add the localization of your library with the environmental variable to know where to find them:

export LD_LIBRARY_PATH=.:$LD_LIBRARY_PATH

What are the advantages and drawbacks of each of them?

Static linking:

Dynamic linking:

  • The size of a.out is smaller.
  • You can run several programs which the same library functions because you called it from the memory and it is more efficiently
  • We don’t need to compile the source files again if we modify any library functions
  • The executable files are not self-sufficient. It means that will always depend on the version of DLL. For example, if we change the functions in the library, maybe in the future the executable file will not compile!
executable bash to create a library with all file C typle and then use the file *.o to create de DLL
you compile your main and create your executable file with the dynamic library, then you ran your executable problem, according to the image , in this case is “./len”

--

--

--

Software engineer in progress

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Bifrost Testnet NFT Badges & Rewards Distribution Plan

Check Out My Package… My WordPress Package!

Optimize Water Distribution in a Village

So, you just built your GPU rig for doing Deep Learning… now what?

Using Telepresence to intercept microservices on a Kubernetes cluster

10 Awesome Tech-Related YouTube Channels You Should Watch

Introducing TerraGoat, a vulnerable-by-design Terraform training project by Bridgecrew

Introducing Session to Flutter

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Katherine Soto

Katherine Soto

Software engineer in progress

More from Medium

Score Algorithm in ElasticSearch: BM25

HTTP request-response flow: for dummies

The differences between static and dynamic libraries

CS373 Spring 2022: Sahran Hashim