Libraries In Programing Languages

C: <functions.h>             | PYTHON: <functions.py>
int sum(int a, int b); | def sum(a, b):
<functions.c> | return a + b
#include "functions.h" |
int sum(int a, int b) |
{ |
return(a + b); |
} |
C: <main.c>                 | PYTHON: <main.py>
#include "functions.h" |from functions import sum
int main() |print(sum(2, 2))
{ |
int r = sum(2, 2); |
printf("%i", r); |
return(0); |
} |
gcc -c functions.c -o functions.o
ar -rc libfunctions.a functions.o
C: <main.c>            
#include "functions.h"
int main()
{
int r = sum(2, 2);
...
}
gcc main.c -L . -functions
./a.out
gcc functions.c -c -fPIC
gcc functions.o -shared -o libfunctions.so
export LD_LIBRARY_PATH=.:$LD_LIBRARY_PATH . /libfunctions.so
gcc main.c
./a.out
nm functions.o // nm functions.so Also works
functions.o:
0000000000000000 T sum

--

--

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