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: tt: 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..

Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com