Question about linker errors when using slices
doob at me.com
Sat Sep 19 06:24:17 UTC 2020
On 2020-09-19 04:45, tspike wrote:
> I’ve been using D for personal projects for almost a year now and I
> really love it. I recently ran across a linker error that I’m a little
> confused by. Consider the following files:
> module platform;
> import app;
> struct PlatformData
> AppData a;
> void main()
> module app;
> struct AppData
> //int* items;
> int items;
> If you only compile platform.d, the linker will complain about
> “undefined references.” This is true when using dmd and gdc, though
> platform.d compiles just fine when using ldc. But the file only fails to
> compile when the “items” member of AppData is a slice; if “items” is an
> int* platform.d will compile.
> The linker spits the following:
> undefined reference to `_D3app7AppData9__xtoHashFNbNeKxSQBeQBdZm'
> undefined reference to `_D3app7AppData11__xopEqualsFKxSQBdQBcKxQjZb'
> I was just wondering if anyone knows if this behavior is expected or if
> this is a compiler bug. Thank you in advance for your time!
You should compile both files. I'm guessing LDC might be doing some form
of optimization to figure out that it doesn't need those symbols.
> PS: I hope this is the right sub-forum for asking this sort of question!
More information about the Digitalmars-d-learn