gpt4 book ai didi

c++ - 使用 GameKit 时将源文件类型更改为 Objective-C++ 会导致链接器错误

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:39:11 24 4
gpt4 key购买 nike

所以我在我的 Objective-C 应用程序上使用 Xcode 6.1。我的应用使用 GameKit 框架。

我试图从我的 GameViewController(它是 Objective-C 源代码)调用外部 C++ 方法。

为了编译 GameViewController.mm,我必须手动将类型设置为“Objective-C++ Source”。

但是,即使源代码现在可以编译,它也无法链接到:

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

我只能通过将类型设置回“Objective-C Source”并删除对外部 C++ 函数的调用来消除链接器错误。

如果我的源代码被编译为“Objective-C++ Source”而不是“Objective-C Source”类型,为什么链接器会失败?

请注意,我在构建阶段正确链接到 GameKit。

最佳答案

好的。事实证明这是一个奇怪的,但是:

我正在链接到 GameKit,而不是 GLKit。修复:也链接到 GLKit。

现在,奇怪的是,如果 View Controller 是作为 Objective-C 源构建的,那么不链接 GLKit 不会导致任何问题。如果构建为 Objective-C++ 源代码,它确实会导致问题。

奇怪,但确实如此。

关于c++ - 使用 GameKit 时将源文件类型更改为 Objective-C++ 会导致链接器错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27139655/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com