Unix Programming - dlsym failed

This is Interesting: Free IT Magazines  
Home > Archive > Unix Programming > July 2007 > dlsym failed





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author dlsym failed
shahan.am@gmail.com

2007-07-09, 1: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..

Paul Pluzhnikov

2007-07-10, 1: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 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

> 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.
shahan.am@gmail.com

2007-07-11, 7:21 am

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.

Paul Pluzhnikov

2007-07-11, 1: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.
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com