Creating a shared library and loading it
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Programming > Creating a shared library and loading it




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    Creating a shared library and loading it  
abhi147@gmail.com


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
08-26-06 12:45 PM

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 am I doing wrong ?

Thanks !






[ Post a follow-up to this message ]



    Re: Creating a shared library and loading it  
spibou@gmail.com


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
08-26-06 12:45 PM

abhi147@gmail.com wrote:

> 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 am I doing wrong ?
>
> Thanks !

In the line
handle = dlopen ("library.so", RTLD_LAZY);
replace "library.so" by "./library.so" or even
better by an absolute pathname.

Spiros Bousbouras






[ Post a follow-up to this message ]



    Re: Creating a shared library and loading it  
abhi147@gmail.com


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
08-28-06 06:30 AM


spibou@gmail.com wrote:

> abhi147@gmail.com wrote:
> 
>
> In the line
> handle = dlopen ("library.so", RTLD_LAZY);
> replace "library.so" by "./library.so" or even
> better by an absolute pathname.
>
> Spiros Bousbouras


Thanks a lot ! . It worked :-)






[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 04:04 AM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register