c++ - 不从 "HelloWorld"场景开始时出现链接器错误

标签 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

最佳答案

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

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

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

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

关于c++ - 不从 "HelloWorld"场景开始时出现链接器错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28355615/

相关文章:

gcc - section属性中的“aw”标志是什么意思?

c++ - 我怎样才能调用另一个类的方法?

objective-c - 文本字段中的 Xcode NSString

linker - 将 64 位 glibc 库静态链接到二进制文件

objective-c - 将 CIImage 转换为 NSImage

linux - 我需要将所有线程调度策略设置为 SCHED_RR 以提高线程优先级吗?

C++ 工厂模式使用模板进行自注册

c++ - 为什么标准不允许 std::for_each 在无效的随机访问迭代器范围内具有明确定义的行为?

c++ - 是否可以将 "print"gnuplot 的输出直接输出到 STDOUT?

c++ - 如何将多个参数传递给 pcap_loop()/pcap_handler()?