Real simple unresolved external symbols question...

kinke noone at nowhere.com
Wed Feb 10 23:48:04 UTC 2021


On Tuesday, 9 February 2021 at 19:37:17 UTC, WhatMeWorry wrote:
>
> I'm trying to create a super simple dynamic library consisting 
> of two files:
>
>
>  ------------ file2.d ----------------------
> extern(D):
>     double addEight(double d) { return (d + 8.0); }
> 	
> ------------ fileB.d ----------------------
> extern(D)
> {
>     string concatSuffix(string s) { return (s ~ ".ext"); }
> }
>
>
>>dmd -m64 -c file2.d
>>dmd -m64 -c fileB.d
> creates file2.obj and fileB.obj files
>
> link.exe /DLL /NOENTRY file2.obj fileB.obj msvcrt.lib

If you go the easy route and use LDC, everything works:

ldc2 -shared file1.d file2.d
=> file1.dll

Or, if you really prefer separate compile + link:

ldc2 -c file1.d
ldc2 -c file2.d
ldc2 -shared file1.obj file2.obj

Use `-v` to see what the actual link.exe cmdline is, and notice 
the MSVC and Windows libs that are implicitly added. - IIRC, DMD 
only embeds these system libs into the object file containing 
main/DllMain (and you have none), whereas LDC adds them to the 
linker cmdline.


More information about the Digitalmars-d-learn mailing list