Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot put Objective-C classes in structs #19541

Open
dlangBugzillaToGithub opened this issue Feb 23, 2019 · 1 comment
Open

Cannot put Objective-C classes in structs #19541

dlangBugzillaToGithub opened this issue Feb 23, 2019 · 1 comment
Labels
Arch:x86_64 Issues specific to x86_64 Feature:extern (C/C++/Obj-C) interfacing to C, C++, Objective-C code P2 Severity:major

Comments

@dlangBugzillaToGithub
Copy link

Jacob Carlborg (@jacob-carlborg) reported this on 2019-02-23T11:32:13Z

Transferred from https://issues.dlang.org/show_bug.cgi?id=19694

CC List

Description

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.
@dlangBugzillaToGithub
Copy link
Author

destructionator commented on 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.

@thewilsonator thewilsonator added the Feature:extern (C/C++/Obj-C) interfacing to C, C++, Objective-C code label Dec 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Arch:x86_64 Issues specific to x86_64 Feature:extern (C/C++/Obj-C) interfacing to C, C++, Objective-C code P2 Severity:major
Projects
None yet
Development

No branches or pull requests

2 participants