digitalmars.D - What to do about implicit linking with D DLLs that import Phobos
- Andrej Mitrovic <andrej.mitrovich gmail.com> May 20 2011
It turns out implicit linking with D DLLs which import certain Phobos modules does not work. First, example which works: [dll.d] -> initialization and entry point https://gist.github.com/984095 [mydll.d] -> exports a single function 'foo' (P.S. you don't need a .def file if you export your functions via the export keyword) https://gist.github.com/984097 [driver.d] -> app that will use the DLL https://gist.github.com/984098 We compile the DLL, generate an import library and .di header files : dmd -ofmydll.dll mydll.d dll.d -H -L/IMPLIB Then we compile the app: dmd driver.d -I. mydll.lib Everything works fine! If you delete the DLL the app will not run, which is what you want. Now, inside mydll.d we add an import to another phobos module: [mydll.d] -> updated mydll module https://gist.github.com/984099 We compile the DLL again: dmd -ofmydll.dll mydll.d dll.d -H -L/IMPLIB We try to compile the app: dmd driver.d -I. mydll.lib And boom! Look: OPTLINK (R) for Win32 Release 8.00.12 Copyright (C) Digital Mars 1989-2010 All rights reserved. http://www.digitalmars.com/ctg/optlink.html driver.obj(driver) Error 42: Symbol Undefined _D5mydll12__ModuleInfoZ --- errorlevel 1 I've reported this here: http://d.puremagic.com/issues/show_bug.cgi?id=6019 But I'm not sure how this can be resolved, and I haven't seen bug reports about it before or any discussions about it (please do provide links if you know about discussion about this bug/behavior).
May 20 2011