delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2002/04/08/18:32:07

Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sources.redhat.com/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sources.redhat.com/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
Message-ID: <4864.65.200.9.2.1018305123.squirrel@portal.embedded-guru.com>
Date: Mon, 8 Apr 2002 15:32:03 -0700 (PDT)
Subject: Re: Problem with dlopen
From: "Frank Motta" <fmotta AT embedded-guru DOT com>
To: <lhall AT rfk DOT com>
In-Reply-To: <4.3.1.2.20020408160417.0284fac0@pop.ma.ultranet.com>
References: <4 DOT 3 DOT 1 DOT 2 DOT 20020408160417 DOT 0284fac0 AT pop DOT ma DOT ultranet DOT com>
X-Priority: 3
Importance: Normal
X-MSMail-Priority: Normal
Cc: <cygwin AT cygwin DOT com>
Reply-To: fmotta AT embedded-guru DOT com
MIME-Version: 1.0

OOPS!!!!
Thanks - I actually caught that before sending the email - that didn't
seem to fix it either...

below is a revised file set - :/

Hi,
Maybe I hadn't stated this well --

I need some help creating a dll which I can open and use dlopen and dlsym.

The description is below...

Could someone give me a pointer?

thanks!


      The problem seems to be in the -creation- of the dll.

      the instructions at http://cygwin.com/cygwin-ug-net/dll.html result in
  many link-time errors and the method I -was- using (see below) does not
  export the symbol I need.

      Any ideas?

from testdlopen.c clip *<
---------------------------------------------------------------------


  #include <dlfcn.h> /* dll support */
  #include <stdlib.h> // NULL

  #define MODULE_IMPORT_STR "mod_import"

  int main(int argc, char **argv) {
  char *mod_file_name = "test.dll";
  void *handle;
  void *mod;
  // void *import;
  char *err;
  void *(*import)();

   handle = dlopen(mod_file_name, (RTLD_NOW | RTLD_GLOBAL));
   if ((err = dlerror()) != NULL) {
    printf("Error [%s] in dlopen(%s, %d)\n", err, mod_file_name, (RTLD_NOW |
  RTLD_GLOBAL));
    exit(1);
   }

   if (handle != NULL) {
    /* handle now points to a valid lib */
    dlerror(); /* clear errors */
    import = dlsym(handle, MODULE_IMPORT_STR);

    if ((err = dlerror()) == NULL) {
     mod = (void *)(*import)(argv);
     if (mod != NULL) { /* import it */
     } else {
      printf("Error: execution of imported method failed\n");
      exit(0);
     }
    } else {
     printf("Error [%s] in dlsym(%ul, %s)\n", err, (unsigned int) handle,
  MODULE_IMPORT_STR);
    }
   }

   exit(0);
  }
  ------------------------------------- >8 clip testdlopen.c


from makefile.exe 8<
--------------------------------------------------------------------------



  CC=gcc
  INCLUDE=-I.
  CFLAGS=-Wall
  ifdef debug
  CFLAGS=-g -Wall -DDEBUG -rdynamic
  endif
  #LDFLAGS=-ldl -Wl,-export-dynamic
  LDFLAGS= -Wl,-export-dynamic
  OBJS=util.o output.o types.o hooks.o tsh.o basename.o
  SRCS=output.c types.c tsh.c hooks.c util.c modules.h types.h basename.c

  tsh: $(OBJS)
          $(CC) $(LDFLAGS) -o tsh $(OBJS)

  testdlopen: testdlopen.o
          $(CC) $(LDFLAGS) -o testdlopen testdlopen.o

  testdlopen.o: testdlopen.c
          $(CC) $(INCLUDE) $(CFLAGS) -c testdlopen.c
  ---------------------------------------- >8 clip makefile.exe

The run of testdlopen.exe
Error [dlsym: Win32 error 127] in dlsym(438501376l, mod_import)




  from makefile.dll clip 8<-----------------------------
  # This creates a dll without the exports I need - see def below
  TARGET=simpletest
  DLL_SUFF=.dll
  LIB_SUFF=.a
  DLL_EXP_LIB =$(TARGET)$(DLL_SUFF)$(LIB_SUFF)
  DLL_NAME=$(TARGET)$(DLL_SUFF)
  DLL_LDFLAGS=-Wl,--export-all-symbols
  INCLUDE=

  simpletest.dll: Makefile simpletest.o
          gcc -shared -Wl,--out-implib=$(DLL_EXP_LIB) -o $(DLL_NAME)
  $(DLL_OBJS) $
  (DLL_LDFLAGS) $(DLL_LDLIBS) -Wl,--export-all-symbols
          dlltool --def simpletest.def --dllname simpletest.dll --output-lib
simpl
  etest.a

  #-Wl,simpletest.def
  simpletest.o: simpletest.c ../../modules.h ../../global.h ../../types.h
          $(CC) $(INCLUDE) -c simpletest.c
  ------------------------------------- >8 clip makefile

  from test.def clip 8< ----------------------------------------
  EXPORTS
  mod_import
  ------------------------------------ >8 clip test.def

  from simpltest.c 8< ---------------------------------------------------

  void *foo();
  void *(*export_foo)() = foo;
  void *mod_import(char **argv) {
     return export_foo;
  }

  char *hello = "hello world";
  void *foo() {
          return (void *) hello;
  }
  ------------------------------------ >8 clip test.c
  from nm simpletest.dll | grep T clip 8< ------------------------------
  100010f4 T _DllMain AT 12
  100012a4 T _GetModuleHandleA AT 4
  100012ac T __CTOR_LIST__
  100012b4 T __DTOR_LIST__
  100012ac T ___CTOR_LIST__
  100012b4 T ___DTOR_LIST__
  1000113c T __cygwin_crt0_common AT 8
  10001024 T __cygwin_dll_entry AT 12
  100010d4 T __cygwin_noncygwin_dll_entry AT 12
  10001000 T __end__
  1000125c T _calloc
  1000110c T _cygwin_attach_dll
  10001104 T _cygwin_detach_dll
  1000129c T _cygwin_internal
  10001294 T _cygwin_premain0
  1000128c T _cygwin_premain1
  10001284 T _cygwin_premain2
  1000127c T _cygwin_premain3
  10001254 T _dll_dllcrt0
  10001000 T _end
  1000126c T _free
  10001274 T _malloc
  10001264 T _realloc
  10001000 T end
  100012bc T etext
  --------------------------------------------- >8 nm output

  Notice the -lack- of mod_import!!!





-- 
Frank Motta
fmotta AT embedded-guru DOT com

If you cannot recognize divinity in your fellow man, then you will not
realize the devine within yourself...





--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

- Raw text -


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