Creating Shared Library In Linux
In this tutorial of creating shared library and using with your source code, let us assume that
Let us see whats their in library.cpp
include "library.hpp"
#include <iostream>
using namespace std;
void value_to_be_printed( int x )
{
cout<<"inside shared library"<<endl;
cout << x << "\n";
}
This source code consist of the a function value_to_be_printed Which is just printing a integer value which is passed to it as an argument during function call.
It also consist of a header file library,hpp lets see that too(click_here). It just consist of defination of the value_to_be_printed
After creating a shared library which consist of defination of value_to_be_printed its going to link with main.cpp during run time.
Let's look inside main.cpp
#include <iostream>
#include "library.hpp"
int main ( void )
{
printf("Calling the shared library\n");
value_to_be_printed(10); /*calling value to be printed from shared library */
printf("Completed\n");
return 0;
}
Let's create shared library. You can file all these file in my git repo along with the neccessary step to create a shared library. (link to git)
You can run script.sh file inside the repo which will show you how to create a library.
Thanks and Happy Diwali to All In advance.