www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Using IMPLIB with D dll's

reply Andrej Mitrovic <none none.none> writes:
I'm trying to figure how to use IMPLIB with D DLLs.

The DLL example from the samples folder in DMD:

dll.d > http://pastebin.com/C9NJtqUV
mydll.d > http://pastebin.com/8idbnge0
test.d > http://pastebin.com/6c953BSJ
mydll.def > http://pastebin.com/4enbfbc7

First I'll show how to build without using IMPLIB (since I have the sources). I
use a build command to create the header (interface) files & the import
library, all in one go:

$ dmd -L/IMPLIB -H -ofmydll.dll mydll.d dll.d mydll.def

The dll is cooked, I have an import library (mydll.lib) and the interface
files. Ok, now I link the library with my driver (test.d):

dmd test.d mydll.lib

$ test.exe
 hello dll world

Everything works ok. But, let's say I didn't have the d source files, and all I had was the .dll file, the .def file, and the interface files. I have to create the import lib with IMPLIB. I run the command: $ implib mydll2.lib mydll.def Then I try to link mydll2.lib with the driver: $ dmd test.d mydll2.lib
 Error 42: Symbol Undefined _D5mydll8dllprintFZv

The .lib file seems to be completely empty when I use IMPLIB this way. If instead of using the .def file I use the .lib file directly, like so: $ implib mydll3.lib mydll.dll then I get back a .lib file with some actual symbols (its 2KB compared to the first .lib file, which is 1KB), but I still can't link it: $ dmd test.d mydll3.lib Error 42: Symbol Undefined _D5mydll8dllprintFZv --- errorlevel 1 It seems to be that IMPLIB creates the lib files without underscores before the symbol names. To recap: The first mydll.lib which was created by DMD uses underscores before symbols, the second lib file created by IMPLIB and a .DEF file has no symbols in it, and the third lib file created by IMPLIB and mydll.dll exports symbols without underscores. So, am I missing an important step in building an import library with IMPLIB?
Sep 09 2010
next sibling parent reply Andrej Mitrovic <none none.none> writes:
One other thing. I'm trying to use a tool called objconv, it allows
modification of .lib files, e.g. adding aliases to existing symbols. I was
trying to add aliases to existing symbols and make them have underscores, but
the tool complains that I can't use OMF file formats that have a 16bit word
size (It can only export to 32bit+ word size, but it can read lower ones).

I'm not sure if the tool is broken or if D's .lib files really have a 16bit
word size..? That wouldn't make much sense, I'm not running DOS. :)

The tool can be found here: http://www.agner.org/optimize/#objconv
It was already posted on D NG:
http://www.digitalmars.com/d/archives/digitalmars/D/announce/objconv_2.03_released_includes_.OBJ_disassembler_14246.html

Andrej Mitrovic Wrote:

 I'm trying to figure how to use IMPLIB with D DLLs.

Sep 09 2010
parent Don <nospam nospam.com> writes:
Andrej Mitrovic wrote:
 One other thing. I'm trying to use a tool called objconv, it allows
modification of .lib files, e.g. adding aliases to existing symbols. I was
trying to add aliases to existing symbols and make them have underscores, but
the tool complains that I can't use OMF file formats that have a 16bit word
size (It can only export to 32bit+ word size, but it can read lower ones).
 
 I'm not sure if the tool is broken or if D's .lib files really have a 16bit
word size..? That wouldn't make much sense, I'm not running DOS. :)
 
 The tool can be found here: http://www.agner.org/optimize/#objconv
 It was already posted on D NG:
http://www.digitalmars.com/d/archives/digitalmars/D/announce/objconv_2.03_released_includes_.OBJ_disassembler_14246.html

It's support for D's .obj/.lib files is very limited. The modifications I made to it were enough to let it do asm dumps (which is what I wanted it for), but not enough to perform obj file format conversions.
Sep 10 2010
prev sibling parent Andrej Mitrovic <none none.none> writes:
Forgive me for my ignorance, I neglected to use the /s switch for IMPLIB:

$ implib /s mydll3.lib mydll.dll
$ dmd test.d mydll3.lib
$ test
hello dll world

However I still get a .lib file with no symbols if I use IMPLIB with a .def
file instead of a .dll file. Is this a bug?

Andrej Mitrovic Wrote:

 I'm trying to figure how to use IMPLIB with D DLLs.

Sep 09 2010