Creating and using Dynamic Libraries in “C”

How to Create a Dynamic Library (Linux)

Let’s work with a simple example:

/**
* calculator - Functions calculator
* @a: first number
* @b: second number
* Return: the result of each equation
*/
int add(int a, int b)
{
return (a + b);
}
int sub(int a, int b)
{
return (a - b);
}
int mul(int a, int b)
{
return (a * b);
}
int div(int a, int b)
{
return (a / b);
}
int mod(int a, int b)
{
return (a % b);
}
vagrant@vagrant-ubuntu-trusty-64:~/dynamic_libraries$ gcc -fPIC -c func_ops.c

vagrant@vagrant-ubuntu-trusty-64:~/dynamic_libraries$ ls func_ops.c. func_ops.o
vagrant@vagrant-ubuntu-trusty-64:~/dynamic_libraries$ gcc -shared -o libcalc.so 
vagrant@vagrant-ubuntu-trusty-64:~/dynamic_libraries$ ls
func_ops.c func_ops.o libcalc.so

How to Use a Dynamic Library (Linux)

vagrant@vagrant-ubuntu-trusty-64:~/dynamic_libraries$ export LD_LIBRARY_PATH=$PWD/libcalc.so:

--

--

--

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

Recommended from Medium

Learning DevOps Series Part 6: Preparing for our Jenkins Pipeline

Creating a power-up for your game in Unity

E-Schedule — A Sinatra Application

Multi cloud connection: How to transfer files between Amazon S3 and Azure Blob Storage

Cost Of Microsoft Office For Mac 2016

Azure API Management |SwaggerHub Integrations

Cosmos How-To: Monitoring your validator

A Busy Developer’s Guide to Database Storage Engines — The Basics

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
Andres Pulido

Andres Pulido

More from Medium

Docker using Dockerfile

How to configure Code Pipeline (CICD) using CodeCommit and gitlab

Assign a fixed IP address to a container in Docker-Compose

Intro to Building Container Images with Dockerfiles