[Issue 6019] New: Implicit linking with D DLLs doesn't work
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Mon May 16 16:06:32 PDT 2011
http://d.puremagic.com/issues/show_bug.cgi?id=6019
Summary: Implicit linking with D DLLs doesn't work
Product: D
Version: D2
Platform: Other
OS/Version: Windows
Status: NEW
Severity: normal
Priority: P2
Component: DMD
AssignedTo: nobody at puremagic.com
ReportedBy: andrej.mitrovich at gmail.com
--- Comment #0 from Andrej Mitrovic <andrej.mitrovich at gmail.com> 2011-05-16 16:02:19 PDT ---
Test case: http://dl.dropbox.com/u/9218759/dll_bug.zip
Use the build.bat file or issue these commands:
cd dll
dmd -H -of..\mydll.dll -L/IMPLIB mydll.d
cd..
dmd driver.d -I. dll\mydll.lib
The exported D function is found by the linker, and you can find the name in
the mydll.dll, mydll.lib, and driver.obj files, it has this name:
_D3dll5mydll3fooFiZi
However DMD also generates a mydll.obj file which references this symbol:
_D3dll5mydll12__ModuleInfoZ
This symbol isn't exported in the DLL and you won't find it in the import lib,
and hence the linker error.
Daniel Green made a comment from this thread
http://www.digitalmars.com/d/archives/digitalmars/D/learn/.di_header_imports_with_DLL_symbols_fails_to_link_25571.html:
"Probably unrelated, but this same issue showed up in the GDC backend.
Apparently, the compiler tried to be smart about exporting ModuleInfo
only for those modules that needed it. The fix was to always export it
regardless."
Note that you cannot just pass a .di header file directly to DMD because DMD
will statically compile the mydll.foo function found in the header file, and
the application won't need the DLL anymore.
You also cannot prototype the foo() function directly in driver.d, because this
function will be mangled together with its module name (mangled mydll.driver vs
mangled driver.foo).
The alternative is manually figuring out the mangling of the function name and
using explicit linking via GetProcAddress & friends.
---------------
One more thing: Apparently in v2.053 linking with core.dll_helper doesn't work
anymore:
import core.dll_helper;
void main() {}
Error 42: Symbol Undefined _D4core10dll_helper12__ModuleInfoZ
--- errorlevel 1
Is that a known issue? Linking with core.sys.windows.dll does work though.
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list