How to call a function from a dll created with d ?

frame frame86 at live.com
Sun Jul 3 16:48:52 UTC 2022


On Sunday, 3 July 2022 at 12:54:45 UTC, kinke wrote:
> On Sunday, 3 July 2022 at 08:15:38 UTC, frame wrote:
>> Are you sure?
>
> 100%, just try yourself.
>
> Why would the symbol be defined in the executable? `dimedll.d` 
> isn't compiled into the executable.
>
> The code is using Phobos std.stdio.writeln templates, so the 
> ~20 KB for both exe and DLL are to be expected and IMO 
> absolutely acceptable.
>
> DMD's DLL support is waaay behind LDC's, especially once stuff 
> gets more interesting than trivial examples.

Yeah, I tried LDC and there are differences:

The library file generated by LDC contains the link to the DLL.
The library file generated by DMD is missing that link.

So linking the DMD library would embed the symbol from the 
library - that was my confusion with your example.

Only the -H switch or manual linker command generates a valid 
link to the DLL with DMD but then it's missing all the other 
library contents (also it needs `SimpleDllMain` or bails out 
linking errors to `_calloc` and Windows symbols) :\

Also the -H switch doesn't work correctly. Without supplying 
-L/DLL flag too, I get link error:
```
1561: entry point must be defined
```


More information about the Digitalmars-d-learn mailing list