DavidPeicho / unity-swiftui-example

Integration example of the Unity engine in a SwiftUI-based application
MIT License
70 stars 15 forks source link

Linking error for FrameworkLibAPI #1

Closed torwa closed 3 years ago

torwa commented 3 years ago

The code just works fine for displaying Unity in a SwiftUI app, but has problem with your message API. If this line is added:

FrameworkLibAPI.registerAPIforNativeCalls(...)

the linking process will fail, with error:

Undefined symbols for architecture x86_64:
  "_OBJC_CLASS_$_FrameworkLibAPI", referenced from:
      objc-class-ref in UnityBridge.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Are there any settings that I omitted or you forgot to mention?

Note: I'm trying to run it on simulator, so I chose "Simulator SDK" in Unity's project settings. Anything to do with that?

DavidPeicho commented 3 years ago

It's a linker error, so it looks like you didn't link the Unity framework properly. It's indeed related to the target build on simulator. You should try to build your Unity app for the Simulator SDK and see if that works.

torwa commented 3 years ago

Thanks for your comment!

The Unity app is actually built for the Simulator SDK, as suggested here, otherwise the header file cannot even be found. And if I comment out everything about the FrameworkLibAPI or API, which corresponds to the message mechanism, the Unity part can be successfully initialized and displayed in a SwiftUI app on simulator. It seems that the original Unity framework can be correctly linked, but the message API itself will lead to the linker error.

Anyway, your entire code works well on real devices, that's good enough for me! Thanks for your great work.

Macoron commented 2 years ago

Sorry for necroing old issue, but I believe, I've found a way to fix it for simulators. You would need to use NSClassFromString to call FrameworkLibAPI methods. Read more details in this thread