[ROOT] UnixDynFindSymbol

From: Eddy Offermann (eddy@rentec.com)
Date: Sun Apr 29 2001 - 00:29:42 MEST


Hi Fons and Rene,

I notice that UnixDynFindSymbol is only defined for HPUX. Any particular
reason ?? Maybe one could use dlopen, ...dlsym etc 

Looking at the man page for dlsym:

     Example 1: Using dlopen() and dlsym() to access  a  function
     or data objects.

     The following example shows how one can  use   dlopen()  and
     dlsym() to access either function or data objects.  For sim-
     plicity, error checking has been omitted.

     void       *handle;
     int        *iptr, (*fptr)(int);

     /* open the needed object */
     handle = dlopen("/usr/home/me/libfoo.so.1", RTLD_LAZY);

     /* find the address of function and data objects */
     fptr = (int (*)(int))dlsym(handle, "my_function");
     iptr = (int *)dlsym(handle, "my_object");

     /* invoke function, passing value of integer as a parameter */
     (*fptr)(*iptr);

     Example 2: Using dlsym() to verify that a  particular  func-
     tion is defined.

     The following code fragment shows how dlsym() can be used to
     verify  that a particular function is defined and to call it
     only if it is.

     int (*fptr)();

     if ((fptr = (int (*)())dlsym(RTLD_DEFAULT,
         "my_function")) != NULL) {
             (*fptr)();
     }

Eddy


/______________________________________________________________________________
Func_t TUnixSystem::UnixDynFindSymbol(const char *lib, const char *entry)
{
   // Finds and returns a function pointer to a symbol in the shared library.
   // Returns 0 when symbol not found.

#if defined(R__HPUX) && !defined(R__GNU)
   shl_t handle;

   if (handle = (shl_t)FindDynLib(lib)) {
      Func_t addr = 0;
      if (shl_findsym(&handle, entry, TYPE_PROCEDURE, addr) == -1)
         ::SysError("TUnixSystem::UnixDynFindSymbol", "shl_findsym");
      return addr;
   }
   return 0;
#else
   if (lib || entry) { }

   // Always assume symbol not found
   return 0;
#endif
}



This archive was generated by hypermail 2b29 : Tue Jan 01 2002 - 17:50:43 MET