Thread overview
Real simple unresolved external symbols question...
Feb 09, 2021
WhatMeWorry
Feb 10, 2021
Kagamin
Feb 10, 2021
Rumbu
Feb 10, 2021
Ferhat Kurtulmuş
Feb 10, 2021
WhatMeWorry
Feb 11, 2021
H. S. Teoh
Feb 11, 2021
kinke
Feb 11, 2021
Imperatorn
Feb 10, 2021
kinke
February 09, 2021
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

fileB.obj : error LNK2019: unresolved external symbol _D12TypeInfo_Aya6__initZ referenced in function _D5fileB12concatPrefixFAyaZQe
fileB.obj : error LNK2019: unresolved external symbol _d_arraycatT referenced in function _D5fileB12concatPrefixFAyaZQe

Ok. I find _d_arraycatT in the D website at:

https://dlang.org/library/rt/lifetime/_d_arraycat_t.html

So I thought, this symbol will be in phobos64.lib.  But when I add it to the command, all hell breaks loose:


>link.exe /DLL /NOENTRY file2.obj fileB.obj msvcrt.lib phobos64.lib

phobos64.lib(bits_23fa_21c.obj) : error LNK2001: unresolved external symbol memcpy
 o  o  o
file2.dll : fatal error LNK1120: 57 unresolved externals


So I'm stuck and don't have a clue as to how to continue.

I thought Phobos64.lib was self-contained.  Do I need to add other libraries?  And how do I know which ones?




February 10, 2021
Add libraries that provide missing symbols.
February 10, 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
>
> fileB.obj : error LNK2019: unresolved external symbol _D12TypeInfo_Aya6__initZ referenced in function _D5fileB12concatPrefixFAyaZQe
> fileB.obj : error LNK2019: unresolved external symbol _d_arraycatT referenced in function _D5fileB12concatPrefixFAyaZQe
>
> Ok. I find _d_arraycatT in the D website at:
>
> https://dlang.org/library/rt/lifetime/_d_arraycat_t.html
>
> So I thought, this symbol will be in phobos64.lib.  But when I add it to the command, all hell breaks loose:
>
>
>>link.exe /DLL /NOENTRY file2.obj fileB.obj msvcrt.lib phobos64.lib
>
> phobos64.lib(bits_23fa_21c.obj) : error LNK2001: unresolved external symbol memcpy
>  o  o  o
> file2.dll : fatal error LNK1120: 57 unresolved externals
>
>
> So I'm stuck and don't have a clue as to how to continue.
>
> I thought Phobos64.lib was self-contained.  Do I need to add other libraries?  And how do I know which ones?

You have 2 obj files, and you link them. Where do you want the "self contained" to be present?

The missing symbols in your case are in druntime.lib, not in phobos.


February 10, 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:
>
> [...]

remove /NOENTRY, and include "mixin SimpleDllMain;" in one of the sources. And link with druntime.

link /DLL file2.obj fileB.obj druntime-ldc.lib msvcrt.lib
February 10, 2021
On Wednesday, 10 February 2021 at 11:38:00 UTC, Ferhat Kurtulmuş wrote:
> 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:
>>
>> [...]
>
> remove /NOENTRY, and include "mixin SimpleDllMain;" in one of the sources. And link with druntime.
>
> link /DLL file2.obj fileB.obj druntime-ldc.lib msvcrt.lib


Okay, thanks. Then why does the README.md at

https://github.com/dlang/druntime

say "Runtime is typically linked together with Phobos in a release such that the compiler only has to link to a single library to provide the user with the runtime and the standard library."
February 10, 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.
February 10, 2021
On Wed, Feb 10, 2021 at 11:35:27PM +0000, WhatMeWorry via Digitalmars-d-learn wrote: [...]
> Okay, thanks. Then why does the README.md at
> 
> https://github.com/dlang/druntime
> 
> say "Runtime is typically linked together with Phobos in a release such that the compiler only has to link to a single library to provide the user with the runtime and the standard library."

Probably outdated information.  Somebody should submit a PR for it. ;-)


T

-- 
Let X be the set not defined by this sentence...
February 11, 2021
On Thursday, 11 February 2021 at 00:18:23 UTC, H. S. Teoh wrote:
> On Wed, Feb 10, 2021 at 11:35:27PM +0000, WhatMeWorry via Digitalmars-d-learn wrote: [...]
>> Okay, thanks. Then why does the README.md at
>> 
>> https://github.com/dlang/druntime
>> 
>> say "Runtime is typically linked together with Phobos in a release such that the compiler only has to link to a single library to provide the user with the runtime and the standard library."
>
> Probably outdated information.  Somebody should submit a PR for it. ;-)

It basically says there's no separate libdruntime with DMD, it's included in libphobos2 (unlike LDC). So 'runtime' in the context of the druntime repo is 'druntime', not 'C runtime and other platform libs' libphobos/druntime depend on.

February 11, 2021
On Thursday, 11 February 2021 at 00:18:23 UTC, H. S. Teoh wrote:
> On Wed, Feb 10, 2021 at 11:35:27PM +0000, WhatMeWorry via Digitalmars-d-learn wrote: [...]
>> Okay, thanks. Then why does the README.md at
>> 
>> https://github.com/dlang/druntime
>> 
>> say "Runtime is typically linked together with Phobos in a release such that the compiler only has to link to a single library to provide the user with the runtime and the standard library."
>
> Probably outdated information.  Somebody should submit a PR for it. ;-)
>
>
> T

Can someone in here update the docs?