Search code examples
c++macoslinkercocos2d-x

linker error when not starting with "HelloWorld" scene


I've just started to use Cocos2d-x c++ (Version 3.4), and I'm trying to build a simple game for Mac, but when I change this line in AppDelegate.cpp

auto scene = HelloWorld::createScene();

to my custom Scene

auto scene = KeyboardScene::createScene();

I get this linker error:

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).

I can't figure out know what I'm missing here, any help is appreciated, thank you.

If you want to see the custom class source visit:

http://pastebin.com/F0NhSUWf


Solution

  • This probably can be result of one of two things.

    First. You do not define KeyboardScene::createScene() symbol at all. Check that you actually have the definition of KeyboardScene:: createScene() in you KeyboardScene.cpp file. You KeyboardScene.cpp should contain code like this:

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

    Second. You do not compile KeyboardScene.cpp or do not link resulting KeyboardScene.o into the executable. Check that KeyboardScene.cpp is included to build set of the application target as in the sample here. Sample image