dmd
dmd copied to clipboard
Mismatching mixin IDs cause link failure
bug.d:
template O() {}
mixin template G() {
void Foo() {}
}
final class D {
alias L = () {};
mixin G;
}
bug_client.d:
import bug;
void main() { (new D()).Foo(); }
Result:
$ dmd -lib -of=lib.a bug.d && dmd -c bug_client.d && dmd bug_client.o lib.a
/nix/store/z3za8hfc24wb117s50p8b10agjkgm039-binutils-2.44/bin/ld: bug_client.o: in function `D main':
bug_client.d:(.text._Dmain[_Dmain]+0xd): undefined reference to `bug.D.__mixin2.Foo()'
collect2: error: ld returned 1 exit status
Error: undefined reference to `bug.D.__mixin2.Foo()`
referenced from `_Dmain`
perhaps a library needs to be added with the `-L` flag or `pragma(lib, ...)`
Error: linker exited with status 1
/nix/store/pbqah1qk4b5y14fqinr1h8zvhqy71v81-gcc-wrapper-14.3.0/bin/cc bug_client.o -o bug_client -m64 -Xlinker --export-dynamic lib.a -L/home/vladimir/opt/nix/libs/lib -L/nix/store/0a7bmmq6a64d0skl1bav2ka5ag6wdszf-dmd-2.110.0/lib -Xlinker -Bstatic -lphobos2 -Xlinker -Bdynamic -lpthread -lm -lrt -ldl
The mixin IDs are mismatching:
$ nm lib.a | grep Foo
0000000000000000 W _D3bug1D8__mixin33FooMFZv
$ nm bug_client.o | grep Foo
U _D3bug1D8__mixin23FooMFZv