delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2004/08/16/22:30:30

X-Authentication-Warning: delorie.com: mail set sender to djgpp-bounces using -f
From: NoEmailAds AT execpc DOT com (Chris Giese)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: How to port djgpp _dxe_load?
Date: Tue, 17 Aug 2004 02:16:57 GMT
Organization: PROPULSION GROUP
Message-ID: <41216a63.1144959@news.voyager.net>
References: <20040816164652 DOT GA776 AT kendall DOT sfbr DOT org>
X-Newsreader: Forte Free Agent 1.21/32.243
X-Complaints-To: abuse AT supernews DOT com
Lines: 35
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019