Mail Archives: djgpp/2004/08/16/22:30:30
JT Williams <jeffw AT darwin DOT sfbr DOT org> wrote:
>I am using the following djgpp-specific code
>to load/execute an external function:
{snip}
>Is this code too djgpp-specific to port (easily)
>to another OS (in particular, Solaris)? Any tips
>on how to do so would be appreciated.
I think UNIX systems use dlopen(), dlsym(), dlerror(), and dlclose().
An example from the dlfcn(3) man page:
#include <stdio.h>
#include <dlfcn.h>
int main(int argc, char **argv) {
void *handle;
double (*cosine)(double);
char *error;
handle = dlopen ("libm.so", RTLD_LAZY);
if (!handle) {
fprintf (stderr, "%s\en", dlerror());
exit(1);
}
cosine = dlsym(handle, "cos");
if ((error = dlerror()) != NULL) {
fprintf (stderr, "%s\en", error);
exit(1);
}
printf ("%f\en", (*cosine)(2.0));
dlclose(handle);
return 0;
}
- Raw text -