Creating a shared library and loading it

A

abhi147

Hi ,

I am trying to create a shared library and trying to load it
usinf dlopen() function . My code and steps to create and load the *.so
is :

/*** test.c ***/
#include <stdio.h>
void test()
{
printf("Hello World\n");
}

/*** Steps for *.so creation ***/
bash-3.00# gcc -fPIC -c test.c
bash-3.00# gcc -o library.so -shared test.o
bash-3.00# gcc -o library.so -Wl,-h,library.so -shared test.o

/***load.c***/
#include <stdio.h>
#include <dlfcn.h>

int main(int argc,char **argv)
{
void *handle;
char *error;

handle = dlopen ("library.so", RTLD_LAZY);
if (!handle) {
fprintf (stderr, "%s\n", dlerror());
exit(1);
}

}

/*** Steps for creating load executable***/
bash-3.00# gcc test.c -ldl

When I run the "a.out" it gives me the following error

bash-3.00# ./a.out
ld.so.1: a.out: fatal: library.so: open failed: No such file or
directory

Can someone tell me .. where I am wrong ?

Thanks !
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top