- Subject: aix, dlopen(NULL, .), and gcc
- From: Scott Dudley <scott at telesoft dot com>
- Date: Mon, 13 Nov 2000 19:26:53 -0700
- Newsgroups: comp.unix.programmer,comp.unix.aix,com.lang.c
- Organization: Telesoft Corp.
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.