From: Matthew B. <mat...@ea...> - 2007-02-04 00:33:33
|
I've been a happy user of swig for a while. However recently I've tried to use swig to interface a dll to a convenient scripting language (I tried python and tcl.) and have run into problems. The dll contains several functions that use the standard call protocol and it also has an MS VC++ compatible library (.lib) stub. The functions, however, were not generated from C or C++ code. Let's say for example that I call the project test and I have a few simple C style function prototypes in test.h. The library we'll call lib.dll and lib.lib. I create an interface file test.i that simply includes test.h to create test_wrap.c. Now how do I create the interface dll for say tcl? One might naively try from the command line using MS VC++ 7.0 (actually the 2003 toolkit): cl.exe $(TCL_Inc) /D__WIN32__ /LD test_wrap.c lib.lib $(TCL_libpath)\tcl84.lib /link /OUT:test.dll But this creates a dll with the symbols Test_Init Test_SafeInit but does not contain any of the symbols in the original dll test.dll. When the dll is loaded into tcl, none of lib.dll's routines are visible. (For the python case, the dll doesn't load at all.) So it appears that one has to create a .def file and try to export the symbols to test.dll. Unfortunately in my case, test.dll has two symbols for each routine, a decorated and undecorated symbol. This seems to cause link.exe to choke, when trying to create a new .dll. What I really need is a way to append Test_Init and Test_SafeInit into the original (or a copied) lib.dll. This limitation appears to exist for most of the interfaces that rely on loading a dll. Lua may be a little different since it builds a separate table with the external references, and I have gotten this to work in that case. I really don't know what a clean solution to this is, but it certainly happens often enough (whenever there are libraries in dlls with no source code available), that there ought to be a nice way to do this. |