【问题标题】:linker error when not starting with "HelloWorld" scene未从“HelloWorld”场景开始时出现链接器错误
【发布时间】:2015-02-05 22:55:14
【问题描述】:

我刚开始使用 Cocos2d-x c++(版本 3.4),我正在尝试为 Mac 构建一个简单的游戏,但是当我在 AppDelegate.cpp 中更改此行时

auto scene = HelloWorld::createScene();

到我的自定义场景

auto scene = KeyboardScene::createScene();

我收到此链接器错误:

Undefined symbols for architecture x86_64:
  "KeyboardScene::createScene()", referenced from:
      AppDelegate::applicationDidFinishLaunching() in AppDelegate.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation).

我不知道我在这里缺少什么,感谢您的帮助,谢谢。

如果要查看自定义类源码访问:

http://pastebin.com/F0NhSUWf

【问题讨论】:

  • 您是否在 AppDelegate 中包含 KeyboardScene.h?您在 pastebin 中有重复的代码,这可能是相关的。
  • 不是#include 问题,因为代码可以编译,但没有链接。确保您为 x86_64(而不是 IOS arm)链接到正确的 .dynlib

标签: c++ macos linker cocos2d-x


【解决方案1】:

这可能是两件事之一的结果。

首先。您根本没有定义 KeyboardScene::createScene() 符号。检查您的KeyboardScene.cpp 文件中是否确实有KeyboardScene:: createScene() 的定义。你KeyboardScene.cpp 应该包含这样的代码:

KeyboardScene::createScene() {
    // function body here
}

第二。您不编译 KeyboardScene.cpp 或不将生成的 KeyboardScene.o 链接到可执行文件中。检查是否包含KeyboardScene.cpp 以构建应用程序目标集,如此处的示例中所示。

【讨论】:

  • 谢谢,Xcode 默认只包含在 iOS 目标中。
  • 静态文件夹(蓝色图标)怎么样?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-07-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-12-11
  • 1970-01-01
相关资源
最近更新 更多