iOS整合Unity项目加入SceneKit报错Undefined symbols for architecture arm64: "_OBJC_CLASS_$_SCNLight"

问题描述

在Unity导出的iOS项目中进行开发时,自定义的视图中使用SceneKit时报错:

ld: warning: arm64 function not 4-byte aligned: ltmp0 from /Users/hustlion/idc/20161217园博园/HolyEvilCapture/Libraries/libiPhone-lib.a(unwind_test_arm64.o)
ld: warning: arm64 function not 4-byte aligned: _unwind_tester from /Users/hustlion/idc/20161217园博园/HolyEvilCapture/Libraries/libiPhone-lib.a(unwind_test_arm64.o)
Undefined symbols for architecture arm64:
  "_OBJC_CLASS_$_SCNLight", referenced from:
      objc-class-ref in playerInfoViewController.o
  "_OBJC_CLASS_$_SCNCamera", referenced from:
      objc-class-ref in playerInfoViewController.o
  "_SCNLightTypeOmni", referenced from:
      -[playerInfoViewController addScene] in playerInfoViewController.o
  "_OBJC_CLASS_$_SCNNode", referenced from:
      objc-class-ref in playerInfoViewController.o
  "_OBJC_CLASS_$_SCNScene", referenced from:
      objc-class-ref in playerInfoViewController.o
  "_SCNLightTypeAmbient", referenced from:
      -[playerInfoViewController addScene] in playerInfoViewController.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

原因分析

笔者在单独写UI界面(没有与Unity整合时),使用SceneKit只需要引用对应的头文件。但是与Unity整合后,发现需要在Build Phases中引入SceneKit.framework才能正常编译。可能是Unity导出项目的某些编译设定导致了要额外引入SceneKit.framework才能使用SceneKit。

解决办法

在Build Phases中引入SceneKit.framework,如图所示:
iOS整合Unity项目加入SceneKit报错Undefined symbols for architecture arm64:

小结

遇到Undefined symbols for architecture arm64: "_OBJC_CLASS_$_SCNLight"类似的错误时,可以先考虑是否有相应的framework可以引入。

参考

  • IOS编译报错:objc-class-ref in AppDelegate.o之解决方案 Xcode7
  • iOS 中的 armv7,armv7s,arm64,i386,x86_64 都是什么
  • No architectures to compile for (ONLY_ACTIVE_ARCH=YES, active arch=x86_64, VALID_ARCHS=armv7 armv7s)
  • 彻底解决OBJC_CLASS$_某文件名”, referenced from:问题(转)

你可能感兴趣的:(Xcode,iOS,Apple)