Dynamic or shared libraries in C

Dynamic linking

Dynamic libraries

Static linking

1. How to create the dynamic library

gcc -shared -Wl,-soname,whatevername.so -o whatevername.so *.o

2. How to use a dynamic library

$ LD_LIBRARY_PATH=$(pwd):$LD_LIBRARY_PATH
$ export LD_LIBRARY_PATH
ldd my_app
yourlibrarie.so.1 (0x00007ffd385f7000)
libmy_shared.so => /home/cristian/folder/youlibraries.so (0x00007f3fad401000)
libc.so.6 => /lib64/libc.so.6 (0x00007f3fad21d000)
/lib64/ld-linux-x86-64.so.2 (0x00007f3fad408000)
file my_app
my_app: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=26c677b771122b4c99f0fd9ee001e6c743550fa6, for GNU/Linux 3.2.0, not stripped
nm yourlibrarie.so

--

--

--

Developer | Software engineer in process | Facebook | instagram | Student in Holberton school

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

Recommended from Medium

Instagram stories in your Flutter app

Top 10 Most Important ASP.NET MVC Interview Questions

Ingest data from GCS to BQ using Cloud Functions.

Leetcode 443. String Compression

Scaling PostgreSQL: load balancing and healthchecks

How to Debug Web Program like a Pro

Solution for Loops(for, foreach) in RIDE

IntelliJ — Get the most out of your IDE

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
Cristian Mendoza

Cristian Mendoza

Developer | Software engineer in process | Facebook | instagram | Student in Holberton school

More from Medium

Exploring Intel’s One API Architecture.

Code faster with lombok

Best practices to containerize Node.js applications with Docker

Syntax and Data Structures of ES6: Logical Operators, Array.prototype.reduce,