The following code fails to link with DMD 2.085.0-beta.1
extern (Objective-C) class NSObject {}
struct Foo
{
NSObject o;
}
void main() {}
The error is:
Undefined symbols for architecture x86_64:
"__D4main8NSObject7__ClassZ", referenced from:
__D25TypeInfo_xC4main8NSObject6__initZ in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Error: linker exited with status 1
This issue occurs due to no classinfo is outputted for Objective-C classes. This is intentional, but I'm not sure how to fix it. Global, local or TLS variables or instance variables for classes don't require the classinfo, not sure why a struct field requires it.
Comment #1 by destructionator — 2023-09-26T00:13:39Z
I saw this too recently, I think it is because it is trying to reference them for precise gc info.
I hacked around it by wrapping the member in a union {}
struct Foo {
union { NSObject obj; }
}
but i agree it shouldn't require this.
Comment #2 by robert.schadek — 2024-12-13T19:02:32Z