This is the mail archive of the cygwin@sources.redhat.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

creating a dll with imports


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@sourceware.cygnus.com


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]