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]

Re: AW: Linking Dynamic Libraries


There's an easier way -- one command!  'gcc -shared' will create a dll
for you.  Just do:

$(BASE)=foo

  gcc -shared -o cyg$(BASE).dll -Wl,--out-implib=lib$(BASE).dll.a \
    -Wl,--export-all -Wl,--enable-auto-image-base \
    -Wl,--output-def=cyg$(BASE).def $(OBJS)

Grab any of the packages in the 'contrib' directory and look an the
makefiles (you might need to do a minimal 'configure' first, to
customize the Makefile for cygwin before using it as a model)

--Chuck

Jürgen Schuck wrote:
> 
> I'm not sure about the kind of object that 'gcc -shared'
> produces. But I think it won't be what you might expect.
> In Windows shared sobjects are DLL's. You probably will
> have to convert your Makefiles to cproduce DLL's instead
> of UNIX-style .so files.
> 
> I did the same task when porting a TCL-extension from
> UNIX to Cygwin. The Makefile (SVR4) changes from
> 
> libTclDM20.so:
>         ld -G -o $@ $(OBJS)
> 
> to
> 
> LOAD      = TclDM20
> DEF       = $(LOAD).def
> BAS       = $(LOAD).base
> EXP       = $(LOAD).exp
> $(DLL): $(OBJS)
>         echo EXPORTS >$(DEF)
>         nm $+ | grep '^........ [T] _' | sed 's/[^_]*_//' >>$(DEF)
>         $(LD) --base-file $(BAS) -dll -o $@ $+ -e _dll_entry@12 \
>                                 -L`dirname \`gcc -print-file-name=libgcc.a\`` \
>                                 $(LIBS) -lgcc -lcygwin -lkernel32 -lgcc
>         dlltool --as=as -dllname $@ --def $(DEF) \
>                                         --base-file $(BAS) --output-exp $(EXP)
>         $(LD) --base-file $(BAS) $(EXP) -dll -o $@ $+ -e _dll_entry@12 \
>                                 -L`dirname \`gcc -print-file-name=libgcc.a\`` \
>                                 $(LIBS) -lgcc -lcygwin -lkernel32 -lgcc
>         dlltool --as=as -dllname $@ --def $(DEF) \
>                                         --base-file $(BAS) --output-exp $(EXP)
>         $(LD) $(EXP) -dll -o $@ $+ -e _dll_entry@12 \
>                                 -L`dirname \`gcc -print-file-name=libgcc.a\`` \
>                                 $(LIBS) -lgcc -lcygwin -lkernel32 -lgcc
> 
> For further information see
> http://sources.redhat.com/cygwin/docs.html,
> section "Writing DLLs". Reading these docs you
> will find two further modules: dll_init.c and
> dll_fixup.c. I didn't put them into my DLL because
> the resulting DLL crashes the TCL-interpreter.
> 
> Furthermore I found it very helpful to take a
> look into the Makefiles of the DLL-generating
> packages of the Cygwin-distribution: tcl, wish
> and tix.
> 
> Jürgen Schuck
> PCM-Kundenbetreuung
> Business Unit Information
> _________________________________________________
> MATERNA GmbH Information & Communications
> Vosskuhle 37 * 44141 Dortmund
> Tel.: 0231 - 5599 - 191 *  Fax: -272
> Handy: 0172 - 23 70 148  * http://www.materna.de
> 
> --
> Want to unsubscribe from this list?
> Send a message to cygwin-unsubscribe@sourceware.cygnus.com

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