dlsym failed
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 > dlsym failed




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

    dlsym failed  
shahan.am@gmail.com


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


 
07-09-07 06:26 PM

Hi
I want to get a address of a function at runtime by using dlsym. This
is the sample code i have written.
(This is a sample code. In actual implementation _CreateVirtualProcess
in a seperate shared library)

//--Main.cpp
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>
#include <dlfcn.h>
#ifdef SUNOS
#include <sys/filio.h>
#else
#include <sys/ioctl.h>
#endif

extern "C" pid_t _CreateVirtualProcess(void (*func)(int))
{
/*Implementation*/
return getpid();
}

pid_t __CreateVituralProcess(void (*func)(int))
{
static pid_t (*_create_virtual_process)(void (*)(int)) = NULL;
if (_create_virtual_process == NULL)
{
char* zdlerror = dlerror();
void *p = dlsym(RTLD_DEFAULT,
"_CreateVirtualProcess");
_create_virtual_process = (pid_t (*)(void (*)(int)))p;
if ((zdlerror = dlerror()) != NULL)
{
fprintf (stderr, "%s\n", zdlerror);
return -1;
}
}
return (*_create_virtual_process)(func);
}
int main ()
{
printf("pid = %d\n", __CreateVituralProcess(NULL));
return 0;
}
In Solaris SPARC (5.9) with g++ (3.4.6)  i build it by g++ -ott
Main.cpp -DSUNOS.
when executing it fails by giving "ld.so.1: stt: fatal:
_CreateVituralProcess: can't find symbol"..

but Solaris x86 (5.10) with g++ (3.4.3) its working fine.
i tried it in red hat linux with g++ (3.2.3 ) also failed.

what went wrong there ? how should i correct the problem ?

Thank you..






[ Post a follow-up to this message ]



    Re: dlsym failed  
Paul Pluzhnikov


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


 
07-10-07 06:23 PM

shahan.am@gmail.com writes:

> In Solaris SPARC (5.9) with g++ (3.4.6)  i build it by g++ -ott
> Main.cpp -DSUNOS.

That's hard to believe:

$ g++ -ott junk.cpp -DSUNOS
Undefined                       first referenced
symbol                             in file
dlsym                               /tmp/cck2dqmb.o  (symbol belongs to impl
icit dependency /usr/lib/libdl.so.1)
dlerror                             /tmp/cck2dqmb.o  (symbol belongs to impl
icit dependency /usr/lib/libdl.so.1)
ld: fatal: Symbol referencing errors. No output written to tt
collect2: ld returned 1 exit status

> when executing it fails by giving "ld.so.1: stt: fatal:
> _CreateVituralProcess: can't find symbol"..

After adding required '-ldl':

$ g++ junk.cpp -ott -DSUNOS -ldl && ./tt
pid = 10854

> what went wrong there ? how should i correct the problem ?

Hard to tell, since your "story" doesn't appear to be consistent.

Cheers,
--
In order to understand recursion you must first understand recursion.
Remove /-nsp/ for email.





[ Post a follow-up to this message ]



    Re: dlsym failed  
shahan.am@gmail.com


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


 
07-11-07 12:21 PM

On Jul 10, 8:23 pm, Paul Pluzhnikov <ppluzhnikov-...@charter.net>
wrote:
> shahan...@gmail.com writes: 
>
> That's hard to believe:
>
>   $ g++ -ott junk.cpp -DSUNOS
>   Undefined                       first referenced
>    symbol                             in file
>   dlsym                               /tmp/cck2dqmb.o  (symbol belongs to 
implicit dependency /usr/lib/libdl.so.1)
>   dlerror                             /tmp/cck2dqmb.o  (symbol belongs to 
implicit dependency /usr/lib/libdl.so.1)
>   ld: fatal: Symbol referencing errors. No output written to tt
>   collect2: ld returned 1 exit status
> 
>
> After adding required '-ldl':
>
>   $ g++ junk.cpp -ott -DSUNOS -ldl && ./tt
>   pid = 10854
> 
>
> Hard to tell, since your "story" doesn't appear to be consistent.
>
> Cheers,
> --
> In order to understand recursion you must first understand recursion.
> Remove /-nsp/ for email.

thanks Paul
Whats the OS did u use ? Solaris SPARC or x86 ?
In my case it works with Solaris x86 but no with solaris SPARC.






[ Post a follow-up to this message ]



    Re: dlsym failed  
Paul Pluzhnikov


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


 
07-11-07 06:22 PM

shahan.am@gmail.com writes:

> On Jul 10, 8:23 pm, Paul Pluzhnikov <ppluzhnikov-...@charter.net>
> wrote: 

What I am trying to say here is that the info you provided does
not appear to be correct. Did you *really* build with the command
above? If so, perhaps your g++ was configured --with-gnu-ld ?

Output from 'g++ -v' may provide clues.
[vbcol=seagreen]
> Whats the OS did u use ? Solaris SPARC or x86 ?

Solaris 8, 9 and 10 on SPARC all give the same result for me.

Cheers,
--
In order to understand recursion you must first understand recursion.
Remove /-nsp/ for email.





[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 09:01 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