delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2000/09/22/14:21:34

Mailing-List: contact cygwin-help AT sourceware DOT cygnus DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT sources DOT redhat DOT com>
List-Archive: <http://sources.redhat.com/ml/cygwin/>
List-Post: <mailto:cygwin AT sources DOT redhat DOT com>
List-Help: <mailto:cygwin-help AT sources DOT redhat DOT com>, <http://sources.redhat.com/ml/#faqs>
Sender: cygwin-owner AT sources DOT redhat DOT com
Delivered-To: mailing list cygwin AT sources DOT redhat DOT com
From: Daemon Anastas <daemona AT atomtechnology DOT com>
MIME-Version: 1.0
Message-ID: <14795.41668.242229.342620@quark.local>
Date: Fri, 22 Sep 2000 11:19:48 -0700 (PDT)
To: cygwin AT sources DOT redhat DOT com
Subject: creating a dll with imports
X-Mailer: VM 6.72 under 21.1 (patch 8) "Bryce Canyon" XEmacs Lucid

Hello all,
  I am trying to create a dll which contains references to symbols
defined in the exe. This is very easy on solaris, linux or hpux
(dynamic loader scoping rules actually do most of the work).
I seem to be having a problem contriving a solution under windows
with the help cygwin. Anybody have a clue. Here is a simple example:

Here are the cygwin tool invocations and output
gcc -g -DLOOP_TEST -c m.c
gcc -g -DLOOP_TEST -c d.c
dlltool d.o --export-all-symbols --output-def d.def
dlltool m.o --export-all-symbols --exclude-symbols main --output-def m.def
dlltool m.def --def m.def -l m.lib -D m.exe
dllwrap --def d.def -o libd.dll d.o m.lib
gcc -o m.exe m.o

such that m.c contains main() and d.c is the source for the dll.
m.c and d.c follow. Any input is very much appreciated.

				Daemon Anastas


/*         d.c        */
#include <stdlib.h>
 
int dfunc()
{
  printf("in %s()\n", __func__);
#ifdef LOOP_TEST
  foobar();
#endif /* LOOP_TEST */
}


/*         m.c        */
#include <stdlib.h>
#include <stdio.h>
#include <dlfcn.h>
 
main()
{
   char library[] = "./libd.dll";
   char library_symbol[] = "dfunc";
   void *libref;
   int (*symref)();
 
   fprintf(stderr, "DGA: PATH=%s\n", getenv("PATH"));
   libref = dlopen(library, RTLD_LAZY);
   if (libref == 0)
   {
     fprintf(stderr, "Unable to load library '%s'\n", library);
     fprintf(stderr, "  '%s'\n", dlerror());
     return(1);
   }
 
   symref = dlsym(libref, library_symbol);
   if (symref == 0)
   {
     fprintf(stderr, "Unable to find symbol '%s' in library '%s'\n", library_sy$     return(1);
   }
 
   printf("Going to call dynamically loaded symbol\n");
   symref();
   printf("DGA: PATH=%s\n", getenv("PATH"));
   return(0);
}
 
 
#ifdef LOOP_TEST
int foobar()
{
  printf("hi from foobar\n");
}
#endif /* LOOP_TEST */
  


--
Want to unsubscribe from this list?
Send a message to cygwin-unsubscribe AT sourceware DOT cygnus DOT com

- Raw text -


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