Version 0 of How to create mingw32 libraries from DLLs

Updated 2001-10-24 10:44:29

Most binary distributions created for the Windows platform are built using Microsoft Visual C++. This does not mean that you have to develop or build extensions using this compiler (unless they are exporting C++ symbols!). All you need is a suitable link library and then your mingw32 built application can use the same DLLs as everyone else.

To build a useful mingw32 gcc link library from the Tcl dlls we can either work from the DLL or the .LIB files provided. We need to get hold of a copy of sed for win32 from (somewhere) and either use the nm provided with mingw32 gcc or get dumpbin from a Microsoft download site. (I'll fill in some locations eventually).

Working from a DLL

Placing Makefile in your tcl lib directory (...\Tcl\lib) should do what is needed. You need dumpbin and sed in your path plus the exports.sed script given below.

Working from a .LIB file

.LIB files are the normal Microsoft compiler link libraries. Edit the Makefile by uncommenting the *.def sections and commenting the alternative .def sections. The dlltool section remains the same.


 # Makefile - Copyright (C) 2001 Pat Thoyts <[email protected]>
 #
 # How to create a gcc compatible linker library for a DLL from an MSVC 
 # produced .LIB file or DLL. If you want to use the .LIB files, swap over
 # the commented sections and build the .DEF file using the other method.

 DLLTOOL=dlltool --kill-at

 all: libtcl83.a libtk83.a

 #-------------------------------------------------------------------------

 tcl83.def:
         echo EXPORTS > $@
         dumpbin /exports ..\bin\tcl83.dll | sed -nf exports.sed >> $@
 #tcl83.def:
 #        echo EXPORTS > $@
 #        nm tcl83.lib | sed -n "/00000000 T/s/\([^_]*_\)//p" >> $@
 libtcl83.a: tcl83.def
         $(DLLTOOL) --dllname ../bin/tcl83.dll --input-def $< --output-lib $@

 #-------------------------------------------------------------------------

 tk83.def:
         echo EXPORTS > $@
         dumpbin /exports ..\bin\tk83.dll | sed -nf exports.sed >> $@
 #tk83.def:
 #        echo EXPORTS > $@
 #        nm tk83.lib | sed -n "/00000000 T/s/\([^_]*_\)//p" >> $@
 libtk83.a: tk83.def
         $(DLLTOOL) --dllname ../bin/tk83.dll --input-def $< --output-lib $@

 #-------------------------------------------------------------------------

 clean:
         @del tcl83.def
         @del tk83.def

 realclean: clean
         @del libtcl83.a
         @del libtk83.a

 .PHONY: clean realclean


 #
 # Local variables:
 #   mode: makefile
 # End:
 #

 # exports.sed - Copyright (C) 2001 Pat Thoyts <[email protected]>
 #
 # Build an exports list from a Windows DLL.
 #
 /[         ]*ordinal hint/,/^[         ]*Summary/{
  /^[         ]\+[0123456789]\+/{
    s/^[         ]\+[0123456789]\+[ \t]\+[0123456789ABCDEFabcdef]\+[         ]\+[0123456789ABCDEFabcdef]\+[         ]\+\(.*\)/\1/p
  }
 }