Objective-C++ Metal 项目中的链接器错误

Linker errors in Objective-C++ Metal project

我在 El Capitan,我通过 Xcode 创建了一个新项目,我选择了 OS X -> Application -> Game (Language: Objective-C, Game Technology: Metal)

项目最初编译运行没有问题。

然后我将主视图控制器 GameViewController.m 重命名为 GameViewController.mm 以使用 Objective-C++。现在构建时,出现以下链接器错误:

Undefined symbols for architecture x86_64: "_MTKMetalVertexDescriptorFromModelIO", referenced from: -[GameViewController _loadAssets] in GameViewController.o "_OBJC_CLASS_$_MDLMesh", referenced from: objc-class-ref in GameViewController.o "_OBJC_CLASS_$_MTKMesh", referenced from: objc-class-ref in GameViewController.o "_OBJC_CLASS_$_MTKMeshBufferAllocator", referenced from: objc-class-ref in GameViewController.o ld: symbol(s) not found for architecture x86_64

我试过将 Metal headers 包装到 extern "C" {} 中,但没有帮助。

我怎样才能建造它?

原因是 Objective-C 有一个相对较新的功能,其中包含一个 header 会自动将框架添加到您的 link 命令中。 Apple 提供的模板项目默认启用该功能。因此,构建设置中的框架列表是空的。通过将语言更改为 Objective-C++,您已经放弃了该功能并且必须手动添加框架。