Finding the address of a function

MARGUINAUD Philippe philippe.marguinaud@meteo.fr
Fri Apr 19 15:46:00 GMT 2013


Hi all,

I am trying to find the address of a function whose name is known, using
dlopen/dlsym; for instance, I would have expected this program to print
the address of the main function :

#include <dlfcn.h>
#include <stdio.h>

int main ()
{
  void * lib = dlopen (NULL, RTLD_NOW);
  void * sym = dlsym (lib, "main");
  printf ("error=%s\n", dlerror ());
  printf ("sym=0x%llx\n", sym);
}

But instead, I get the following output :

error=./main.x: undefined symbol: main
sym=0x0

How shall I proceed ?

Cheers,

Philippe



More information about the Gcc-help mailing list