If you were trying to port Ray Wenderlich’s SimpleGame tutorial to Android you may have stumbled upon an output similar to the one below when trying to build the project:

SimpleGame/android/obj/local/armeabi/objs-debug/game
    /../../../Classes/HelloWorldScene.o: In function `GameOverScene':
SimpleGame/android/jni/helloworld/../../../Classes
    /GameOverScene.h:44: undefined reference to `vtable for GameOverScene'
SimpleGame/android/obj/local/armeabi/objs-debug/game
    /../../../Classes/HelloWorldScene.o: In function `GameOverScene::node()':
SimpleGame/android/jni/helloworld/../../../Classes
    /GameOverScene.h:46: undefined reference to `GameOverScene::init()'
 
collect2: ld returned 1 exit status

This is because although you created the files (and if you’re using Xcode you are probably going to be able to build & run just fine for iPhone) they have not been added to the build process for Android.

To do that you need to edit the android/jni/helloworld/Android.mk file and update the LOCAL_SRC_FILES definition to include the newly created GameOverScene.cpp file:

LOCAL_SRC_FILES := main.cpp \
../../../Classes/AppDelegate.cpp \
../../../Classes/HelloWorldScene.cpp \
../../../Classes/GameOverScene.cpp

Share this article

Tagged on:     

One thought on “Adding a new .cpp file to the Android build process for Cocos2D-x (or how to handle the undefined reference to `vtable for GameOverScene’ error)

Leave a Reply

Your email address will not be published. Required fields are marked *

Email
Print