Before starting this task I want to say something about "Shared Libraries Pros & Cons"


– They give to you the ability to split your code in conceptually separated sections. Each section will be loaded only if it is needed.

– The same shared library can be used by different programs, in such a way you can save space (it could be useful on small embedded systems)

– Last you can update a program, by updating the shared library without the unistall->re-install process.


– Incompatible versions

– DLL stomping

– Incorrect COM registration

– Shared in-memory modules

– Lack of serviceability

in few word make a serch "DLL Hell"


Now let's start building our shared library. With a bit of fantasy we are going to build an helloworld library.

The source code


#include <stdio.h>

void printHelloWorld(void)


    printf("Hello World!\n");



void printHelloWorld(void);


#include "helloworld.h"

int main(int argc, char **argv)




Building the library

first compile the source

gcc -fPIC -c helloworld.c 

then build the library, (take care, the name of the library must begin with "lib")

$ gcc -shared -o helloworld.o 

Build the application

$ gcc -o mainsl main.c -L. -lhello

$ ls

helloworld.c  helloworld.h  helloworld.o  main.c  mainsl

Launch the mainsl application

$ mainsl
Hello World!

That's all,