不以&#34开头的链接器错误; HelloWorld"现场

时间:2015-02-05 22:55:14

标签: c++ macos linker cocos2d-x

我刚开始使用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

1 个答案:

答案 0 :(得分:6)

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

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

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

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