This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

[Fwd: aix, dlopen(NULL, .), and gcc]




--

Microsoft gives you Windows but Unix gives you the whole house!





i'm using gcc 2.95.2 on aix 4.3.3 attempting to use the NULL path
argument to dlopen().  i've gotten this to work flawlessly on linux but
have been unsuccessful in my efforts to compile/link on aix.  below are
listed two source files, main.c and foo.c.  i want to compile both into
a.out and be able to use dlopen() and dlsym() to obtain a handle or
pointer to foo().  following is excerpt from dlopen() manpage:

If the value of FilePath is NULL, a value for the main application is
returned. This allows dynamically loaded objects to look up symbols in
the main executable, or for an application to examine symbols available
within itself.

main.c:

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


int
main(int argc, char **argv)
{
  void *handle;
  void (*func)(void);
  char *error;


  if ((handle = dlopen (NULL, RTLD_NOW)) == NULL) {
    fputs (dlerror(), stderr);
    exit(1);
  }

  func = dlsym(handle, "foo");
  if ((error = dlerror()) != NULL)  {
    fputs(error, stderr);
    exit(1);
  }

  func();

  dlclose(handle);

  return 0;
}


foo.c:

#include <stdio.h>


void
foo(void)
{
  printf("foo()\n");
}

can anyone tell me how to compile foo.c and ultimately, link both main
and foo into a single executable?

many thanks.





Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]