The traditional interface for runtime loading libraries, that are not
linked by the linker, is based on the Solaris interface.
The functions involved are:
void *dlopen (const char *filename, int flag);
const char *dlerror(void);
void *dlsym(void *handle, char *symbol);
int dlclose (void *handle);
Special symbols: _init, _fini.
flag is a flag which tells the RTLL to resolve symbols now RTLD_NOW or resolve
them as needed RTLD_LAZY. This doesn't resolve references INTO the lib, but
rather references WITHIN the lib.
Solaris documents that _init is called when the lib is loaded, and _fini
is called when it's unloaded.
The typical use is to load the lib, then use dlsym to fetch items from the
lib's symbol table.
Just a note, the easiest way to do dynamic function resolution (which Netscape
totally missed when writing the NSAPI spec, is to create a null terminated array
of function structs:
struct func {
char *name;
void *(function)(arg list);
} func_array[] {
{"function1",function1},
{"function2",function2}};
In your code which loads the library:
struct func_array **functions;
functions=dlsym(handle,"func_array");
Yes, dlsym works to get pointers to global data declarations within shared objects.
See: dlopen(3) {Solaris}
Linux does not come with the appropriate dlfcn.h therefore snarf down some stuff I
put up a LONG time ago at:
ftp.apsoft.com:/pub/Linux/module.tgz
Although the code within bears a different stipulation, I'm placing it under GPL, I'm
too lazy to unpack it and edit the files.
>
> -Erik
>
--Perry
-- Perry Harrington Linux rules all OSes. APSoft () email: perry@apsoft.com Think Blue. /\- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.altern.org/andrebalsa/doc/lkml-faq.html