Linux Basics: Static Libraries vs. Dynamic Libraries

Erika Caoili
Dec 17, 2019 · 4 min read

You came to the right place if you’re wondering how static and dynamic libraries work in C programs. You must be thinking…

Image for post
Image for post
Photo by Edwin Andrade on Unsplash

A Library in Linux

“For instance, if you are building an application that needs to perform math operations, you don’t have to create a new math function for that, you can simply use existing functions in libraries for that programming language.” (“Understanding Shared Libraries In Linux”)

Differences Between Dynamic and Static Libraries

Image for post
Image for post
Dynamic libraries have a “*.so” naming convention and static libraries have an “*.a”.

Advantages and Disadvantages of Dynamic Libraries

Advantages and Disadvantages of Static Libraries

#include "<header file name>"

Dynamic Libraries

gcc -g -fPIC -Wall -Werror -Wextra -pedantic *.c -shared -o
gcc -g -wall -o app app.c

Static Libraries

ar rc liball.a dog.o cat.o bird.o
ranlib liball.a
gcc main.c -L -l<filename>


How to create Static library and Use it in Linux

What is difference between Dynamic and Static library(Static and Dynamic linking)

The Startup

Medium's largest active publication, followed by +756K people. Follow to join our community.

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

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