delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2002/04/12/17:42:50

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
To: cygwin AT cygwin DOT com
X-Injected-Via-Gmane: http://gmane.org/
Path: not-for-mail
From: Frank <fmotta AT embedded-guru DOT com>
Newsgroups: gmane.os.cygwin
Subject: Need help with creation of DLL
Date: Mon, 08 Apr 2002 11:37:24 -0700
Lines: 176
Message-ID: <3CB1E364.A5865936@embedded-guru.com>
References: <30060 DOT 65 DOT 200 DOT 9 DOT 2 DOT 1018045910 DOT squirrel AT portal DOT embedded-guru DOT com>
NNTP-Posting-Host: 65.200.9.2
Mime-Version: 1.0
X-Trace: main.gmane.org 1018291048 20266 65.200.9.2 (8 Apr 2002 18:37:28 GMT)
X-Complaints-To: usenet AT main DOT gmane DOT org
NNTP-Posting-Date: Mon, 8 Apr 2002 18:37:28 +0000 (UTC)
X-Accept-Language: en

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 */
>     //mod->handle = handle;
>     //mod->next = tsh_data.modules->next;
>     //tsh_data.modules->next = mod;
>    } 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!!!
>
> Thanks !!!!
>




--
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