Static vs Dynamic libraries.

library1.cint sum (int a, int b)
return a+b;
int sub (int a, int b)
return a-b;
library1.h#ifndef _LIBRARY_1_H
#define _LIBRARY_1_H
int sum (int a, int b);
int sub (int a, int b);
The Uruguay’s Congress library. Totally unrelated to this article subject but it looks cool.

Creating static libraries using GNU.

#include <stdio.h> 
void fun(void)
printf("fun() called from a static library");
#ifndef LIB_MYLIB_H
void fun(void);#endif
gcc -c lib_mylib.c -o lib_mylib.o
ar rcs lib_mylib.a lib_mylib.o
#include "lib_mylib.h"void main(){
gcc -c driver.c -o driver.o
gcc -o driver driver.o -L. -l_mylib
fun() called from a static library

Creating dynamic libraries using GNU.

gcc *.c -c -fPIC
gcc *.o -shared -o
$ nm -D
0000000000000b1c T _abs
0000000000000b4f T _atoi
0000000000202048 B __bss_start
w __cxa_finalize
0000000000202048 D _edata
0000000000202050 B _end
0000000000000bf4 T _fini
w __gmon_start__
0000000000000910 T _init
0000000000000b13 T _isalpha
0000000000000b2e T _isdigit
0000000000000b0a T _islower
0000000000000b25 T _isupper
w _ITM_deregisterTMCloneTable
w _ITM_registerTMCloneTable
w _Jv_RegisterClasses
0000000000000a75 T main
0000000000000ba9 T _memcpy
0000000000000b97 T _memset
U printf
0000000000000ae0 T _putchar
0000000000000b37 T _puts
0000000000000b59 T _strcat
0000000000000bba T _strchr
0000000000000b89 T _strcmp
0000000000000b41 T _strcpy
0000000000000a9f T _strlen
0000000000000b67 T _strncat
0000000000000b78 T _strncpy
0000000000000bd7 T _strpbrk
0000000000000bc9 T _strspn
0000000000000be5 T _strstr
U write
$ ldd len => (0x00007ffd391b8000) => /home/vagrant/holbertonschool-low_level_programming/0x18-dynamic_libraries/ (0x00007f91da758000) => /lib/x86_64-linux-gnu/ (0x00007f91da388000)
/lib64/ (0x00007f91da960000)




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

Recommended from Medium

Using docker as develop environment

AWS Simple Queue Service (SQS) and Simple Notification Service (SNS)

Site-to-Site VPN on a Single Host Using OpenVPN


Phase 2 Node Operators: Claim Your Nodes

How I became an Android Developer Neophyte

Automation Testing

Configure Python Interpreter On Docker

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
Flavio Orlando

Flavio Orlando

More from Medium

Differences between static and dynamic libraries

CS373 Spring 2022: Dillon Samra

Build WinCE Custom OS Image — Part II

CS 373 Spring 2022: Saran Chockan Blog # 2